30 #include <nsStringGlue.h>
51 sbStringTransformImpl::NormalizeString(
const nsAString & aCharset,
52 PRUint32 aTransformFlags,
53 const nsAString & aInput,
57 CopyUTF16toUTF8(aInput, str);
60 gchar* lowercaseStr = g_utf8_strdown(str.BeginReading(), str.Length());
61 NS_ENSURE_TRUE(lowercaseStr, NS_ERROR_OUT_OF_MEMORY);
62 str.Assign(lowercaseStr);
67 gchar* uppercaseStr = g_utf8_strup(str.BeginReading(), str.Length());
68 NS_ENSURE_TRUE(uppercaseStr, NS_ERROR_OUT_OF_MEMORY);
69 str.Assign(uppercaseStr);
76 PRBool leadingOnly = aTransformFlags &
78 PRBool bypassTest = PR_FALSE;
80 gchar* nonspaceStr = g_utf8_normalize(str.BeginReading(),
83 NS_ENSURE_TRUE(nonspaceStr, NS_ERROR_OUT_OF_MEMORY);
85 glong strLen = g_utf8_strlen(nonspaceStr, -1);
87 for(glong currentChar = 0; currentChar < strLen; ++currentChar) {
89 gchar*
offset = g_utf8_offset_to_pointer(nonspaceStr, currentChar);
90 gunichar unichar = g_utf8_get_char(offset);
91 GUnicodeType unicharType = g_unichar_type(unichar);
94 (unicharType != G_UNICODE_NON_SPACING_MARK &&
95 unicharType != G_UNICODE_COMBINING_MARK &&
96 unicharType != G_UNICODE_ENCLOSING_MARK)) {
97 workingStr += unichar;
104 CopyUTF16toUTF8(workingStr, str);
110 PRBool leadingOnly = aTransformFlags &
112 PRBool bypassTest = PR_FALSE;
114 gchar* nosymbolsStr = g_utf8_normalize(str.BeginReading(),
117 NS_ENSURE_TRUE(nosymbolsStr, NS_ERROR_OUT_OF_MEMORY);
119 glong strLen = g_utf8_strlen(nosymbolsStr, -1);
121 for(glong currentChar = 0; currentChar < strLen; ++currentChar) {
122 gchar* offset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar);
123 gunichar unichar = g_utf8_get_char(offset);
124 GUnicodeType unicharType = g_unichar_type(unichar);
127 PRInt32 numberLength;
129 if (numberLength > 0) {
130 for (glong copychar=0;copychar < numberLength;copychar++) {
131 gchar* copyoffset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar+copychar);
132 gunichar unichar = g_utf8_get_char(copyoffset);
133 workingStr += unichar;
135 currentChar += numberLength-1;
137 bypassTest = PR_TRUE;
143 (unicharType != G_UNICODE_CURRENCY_SYMBOL &&
144 unicharType != G_UNICODE_MODIFIER_SYMBOL &&
145 unicharType != G_UNICODE_MATH_SYMBOL &&
146 unicharType != G_UNICODE_OTHER_SYMBOL)) {
147 workingStr += unichar;
149 bypassTest = PR_TRUE;
153 g_free(nosymbolsStr);
154 CopyUTF16toUTF8(workingStr, str);
161 PRBool leadingOnly = aTransformFlags &
163 PRBool bypassTest = PR_FALSE;
165 gchar* nosymbolsStr = g_utf8_normalize(str.BeginReading(),
168 NS_ENSURE_TRUE(nosymbolsStr, NS_ERROR_OUT_OF_MEMORY);
170 glong strLen = g_utf8_strlen(nosymbolsStr, -1);
172 for(glong currentChar = 0; currentChar < strLen; ++currentChar) {
174 gchar* offset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar);
175 gunichar unichar = g_utf8_get_char(offset);
176 GUnicodeType unicharType = g_unichar_type(unichar);
178 if (aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS) {
179 PRInt32 numberLength;
181 if (numberLength > 0) {
182 for (glong copychar=0;copychar < numberLength;copychar++) {
183 gchar* copyoffset = g_utf8_offset_to_pointer(nosymbolsStr, currentChar+copychar);
184 gunichar unichar = g_utf8_get_char(copyoffset);
185 workingStr += unichar;
187 currentChar += numberLength-1;
189 bypassTest = PR_TRUE;
195 (unicharType == G_UNICODE_LOWERCASE_LETTER ||
196 unicharType == G_UNICODE_MODIFIER_LETTER ||
197 unicharType == G_UNICODE_OTHER_LETTER ||
198 unicharType == G_UNICODE_TITLECASE_LETTER ||
199 unicharType == G_UNICODE_UPPERCASE_LETTER ||
200 unicharType == G_UNICODE_DECIMAL_NUMBER ||
201 unicharType == G_UNICODE_LETTER_NUMBER ||
202 unicharType == G_UNICODE_OTHER_NUMBER) ||
203 (!(aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE) &&
205 workingStr += unichar;
207 bypassTest = PR_TRUE;
211 g_free(nosymbolsStr);
212 CopyUTF16toUTF8(workingStr, str);
215 CopyUTF8toUTF16(str, _retval);
221 sbStringTransformImpl::ConvertToCharset(
const nsAString & aDestCharset,
222 const nsAString & aInput,
225 return NS_ERROR_NOT_IMPLEMENTED;
229 sbStringTransformImpl::GuessCharset(
const nsAString & aInput,
232 return NS_ERROR_NOT_IMPLEMENTED;
void SB_ExtractLeadingNumber(const CHARTYPE *str, PRBool *hasLeadingNumber, PRFloat64 *leadingNumber, PRInt32 *numberLength)