30 #include <nsStringGlue.h>
50 nsTArray<WORD> aExcludeChars[
NTYPES],
51 nsTArray<WORD> aIncludeChars[NTYPES])
53 DWORD actualFlags = 0;
56 actualFlags |= LCMAP_LOWERCASE;
60 actualFlags |= LCMAP_UPPERCASE;
64 aExcludeChars[
C3].AppendElement(C3_DIACRITIC);
65 aExcludeChars[
C3].AppendElement(C3_NONSPACING);
69 aExcludeChars[
C3].AppendElement(C3_LEXICAL);
70 aExcludeChars[
C3].AppendElement(C3_VOWELMARK);
75 aExcludeChars[
C3].AppendElement(C3_LEXICAL);
76 aExcludeChars[
C1].AppendElement(C1_PUNCT);
77 aIncludeChars[
C3].AppendElement(C3_ALPHA);
78 aIncludeChars[
C2].AppendElement(C2_EUROPENUMBER);
79 aIncludeChars[
C1].AppendElement(C1_DIGIT);
80 aIncludeChars[
C1].AppendElement(C1_ALPHA);
81 if (aFlags & sbIStringTransform::TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE) {
82 aExcludeChars[
C1].AppendElement(C1_SPACE);
90 sbStringTransformImpl::NormalizeString(
const nsAString & aCharset,
91 PRUint32 aTransformFlags,
92 const nsAString & aInput,
96 nsString inStr(aInput);
103 nsTArray<WORD> excludeChars[
NTYPES];
104 nsTArray<WORD> includeChars[
NTYPES];
105 DWORD dwFlags =
MakeFlags(aTransformFlags,
112 WCHAR *wszJunk = {0};
113 int requiredBufferSize = ::LCMapStringW(LOCALE_USER_DEFAULT,
115 inStr.BeginReading(),
122 ::LCMapStringW(LOCALE_USER_DEFAULT,
124 inStr.BeginReading(),
126 bufferStr.BeginWriting(requiredBufferSize),
129 NS_ENSURE_TRUE(convertedChars == requiredBufferSize,
130 NS_ERROR_CANNOT_CONVERT_DATA);
132 finalStr = bufferStr;
140 PRBool leadingOnly = aTransformFlags &
142 PRBool bypassTest = PR_FALSE;
143 LPWSTR wszJunk = {0};
144 int requiredBufferSize = ::FoldStringW(MAP_COMPOSITE,
145 inStr.BeginReading(),
152 ::FoldStringW(MAP_COMPOSITE,
153 inStr.BeginReading(),
155 bufferStr.BeginWriting(requiredBufferSize),
158 NS_ENSURE_TRUE(convertedChars == requiredBufferSize,
159 NS_ERROR_CANNOT_CONVERT_DATA);
161 LPWORD ct1 =
new WORD[requiredBufferSize];
162 BOOL success = GetStringTypeW(CT_CTYPE1,
163 (LPWSTR) bufferStr.BeginReading(),
170 return NS_ERROR_CANNOT_CONVERT_DATA;
173 LPWORD ct2 =
new WORD[requiredBufferSize];
174 success = GetStringTypeW(CT_CTYPE2,
175 (LPWSTR) bufferStr.BeginReading(),
183 return NS_ERROR_CANNOT_CONVERT_DATA;
186 LPWORD ct3 =
new WORD[requiredBufferSize];
187 success = GetStringTypeW(CT_CTYPE3,
188 (LPWSTR) bufferStr.BeginReading(),
197 return NS_ERROR_CANNOT_CONVERT_DATA;
200 LPWORD charTypes[
NTYPES] = {ct1, ct2, ct3};
202 for(
int current = 0; current < requiredBufferSize; ++current) {
203 PRBool validChar = PR_TRUE;
204 PRInt32 skipChars = 0;
208 PRInt32 numberLength;
210 if (numberLength > 0) {
211 finalStr.Append(bufferStr.BeginReading() + current, numberLength);
212 current += numberLength-1;
214 bypassTest = PR_TRUE;
222 PRUint32 excludeCharsLength = excludeChars[type].Length();
223 for(PRUint32 invalid = 0; invalid < excludeCharsLength; ++invalid) {
224 if(excludeChars[type][invalid] & charTypes[type][current]) {
225 validChar = PR_FALSE;
232 PRBool found = PR_FALSE;
233 PRBool testedAnything = PR_FALSE;
235 type <=
LASTTYPE && validChar && !found;
237 PRUint32 includeCharsLength = includeChars[type].Length();
238 for(PRUint32 valid = 0; valid < includeCharsLength; ++valid) {
239 testedAnything = PR_TRUE;
240 if (includeChars[type][valid] & charTypes[type][current]) {
246 if (testedAnything &&
248 validChar = PR_FALSE;
254 bypassTest = PR_TRUE;
256 finalStr.Append(bufferStr.CharAt(current));
258 current += skipChars;
272 sbStringTransformImpl::ConvertToCharset(
const nsAString & aDestCharset,
273 const nsAString & aInput,
276 return NS_ERROR_NOT_IMPLEMENTED;
280 sbStringTransformImpl::GuessCharset(
const nsAString & aInput,
283 return NS_ERROR_NOT_IMPLEMENTED;
void SB_ExtractLeadingNumber(const CHARTYPE *str, PRBool *hasLeadingNumber, PRFloat64 *leadingNumber, PRInt32 *numberLength)