28 #include <nsStringGlue.h>
49 sbStringTransformImpl::NormalizeString(
const nsAString & aCharset,
50 PRUint32 aTransformFlags,
51 const nsAString & aInput,
55 CopyUTF16toUTF8(aInput, str);
58 gchar* lowercaseStr = g_utf8_strdown(str.BeginReading(), str.Length());
59 NS_ENSURE_TRUE(lowercaseStr, NS_ERROR_OUT_OF_MEMORY);
60 str.Assign(lowercaseStr);
65 gchar* uppercaseStr = g_utf8_strup(str.BeginReading(), str.Length());
66 NS_ENSURE_TRUE(uppercaseStr, NS_ERROR_OUT_OF_MEMORY);
67 str.Assign(uppercaseStr);
74 PRBool leadingOnly = aTransformFlags &
76 PRBool bypassTest = PR_FALSE;
78 gchar* nonspaceStr = g_utf8_normalize(str.BeginReading(),
81 NS_ENSURE_TRUE(nonspaceStr, NS_ERROR_OUT_OF_MEMORY);
83 glong strLen = g_utf8_strlen(nonspaceStr, -1);
85 for(glong currentChar = 0; currentChar < strLen; ++currentChar) {
87 gchar*
offset = g_utf8_offset_to_pointer(nonspaceStr, currentChar);
88 gunichar unichar = g_utf8_get_char(offset);
89 GUnicodeType unicharType = g_unichar_type(unichar);
92 (unicharType != G_UNICODE_NON_SPACING_MARK &&
93 unicharType != G_UNICODE_COMBINING_MARK &&
94 unicharType != G_UNICODE_ENCLOSING_MARK)) {
95 workingStr += unichar;
102 CopyUTF16toUTF8(workingStr, str);
108 PRBool leadingOnly = aTransformFlags &
110 PRBool bypassTest = PR_FALSE;
112 gchar* nosymbolsStr = g_utf8_normalize(str.BeginReading(),
115 NS_ENSURE_TRUE(nosymbolsStr, NS_ERROR_OUT_OF_MEMORY);
117 glong strLen = g_utf8_strlen(nosymbolsStr, -1);
119 for(glong currentChar = 0; currentChar < strLen; ++currentChar) {
120 gchar* offset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar);
121 gunichar unichar = g_utf8_get_char(offset);
122 GUnicodeType unicharType = g_unichar_type(unichar);
125 PRInt32 numberLength;
127 if (numberLength > 0) {
128 for (glong copychar=0;copychar < numberLength;copychar++) {
129 gchar* copyoffset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar+copychar);
130 gunichar unichar = g_utf8_get_char(copyoffset);
131 workingStr += unichar;
133 currentChar += numberLength-1;
135 bypassTest = PR_TRUE;
141 (unicharType != G_UNICODE_CURRENCY_SYMBOL &&
142 unicharType != G_UNICODE_MODIFIER_SYMBOL &&
143 unicharType != G_UNICODE_MATH_SYMBOL &&
144 unicharType != G_UNICODE_OTHER_SYMBOL)) {
145 workingStr += unichar;
147 bypassTest = PR_TRUE;
151 g_free(nosymbolsStr);
152 CopyUTF16toUTF8(workingStr, str);
159 PRBool leadingOnly = aTransformFlags &
161 PRBool bypassTest = PR_FALSE;
163 gchar* nosymbolsStr = g_utf8_normalize(str.BeginReading(),
166 NS_ENSURE_TRUE(nosymbolsStr, NS_ERROR_OUT_OF_MEMORY);
168 glong strLen = g_utf8_strlen(nosymbolsStr, -1);
170 for(glong currentChar = 0; currentChar < strLen; ++currentChar) {
172 gchar* offset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar);
173 gunichar unichar = g_utf8_get_char(offset);
174 GUnicodeType unicharType = g_unichar_type(unichar);
176 if (aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS) {
177 PRInt32 numberLength;
179 if (numberLength > 0) {
180 for (glong copychar=0;copychar < numberLength;copychar++) {
181 gchar* copyoffset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar+copychar);
182 gunichar unichar = g_utf8_get_char(copyoffset);
183 workingStr += unichar;
185 currentChar += numberLength-1;
187 bypassTest = PR_TRUE;
193 (unicharType == G_UNICODE_LOWERCASE_LETTER ||
194 unicharType == G_UNICODE_MODIFIER_LETTER ||
195 unicharType == G_UNICODE_OTHER_LETTER ||
196 unicharType == G_UNICODE_TITLECASE_LETTER ||
197 unicharType == G_UNICODE_UPPERCASE_LETTER ||
198 unicharType == G_UNICODE_DECIMAL_NUMBER ||
199 unicharType == G_UNICODE_LETTER_NUMBER ||
200 unicharType == G_UNICODE_OTHER_NUMBER) ||
201 (!(aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE) &&
203 workingStr += unichar;
205 bypassTest = PR_TRUE;
209 g_free(nosymbolsStr);
210 CopyUTF16toUTF8(workingStr, str);
213 CopyUTF8toUTF16(str, _retval);
219 sbStringTransformImpl::ConvertToCharset(
const nsAString & aDestCharset,
220 const nsAString & aInput,
223 return NS_ERROR_NOT_IMPLEMENTED;
227 sbStringTransformImpl::GuessCharset(
const nsAString & aInput,
230 return NS_ERROR_NOT_IMPLEMENTED;
void SB_ExtractLeadingNumber(const CHARTYPE *str, PRBool *hasLeadingNumber, PRFloat64 *leadingNumber, PRInt32 *numberLength)