aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llstring.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:27 -0500
committerJacek Antonelli2008-08-15 23:45:27 -0500
commita8a62201ba762e98dff92cf49033e577fc34d8d4 (patch)
tree11f8513c5cdc222f2fac0c93eb724c089803c200 /linden/indra/llcommon/llstring.cpp
parentSecond Life viewer sources 1.18.6.4-RC (diff)
downloadmeta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.zip
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.gz
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.bz2
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.xz
Second Life viewer sources 1.19.0.0
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/llstring.cpp82
1 files changed, 80 insertions, 2 deletions
diff --git a/linden/indra/llcommon/llstring.cpp b/linden/indra/llcommon/llstring.cpp
index b99121e..73c80e7 100644
--- a/linden/indra/llcommon/llstring.cpp
+++ b/linden/indra/llcommon/llstring.cpp
@@ -12,12 +12,12 @@
12 * ("GPL"), unless you have obtained a separate licensing agreement 12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of 13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or 14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlife.com/developers/opensource/gplv2 15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 * 16 *
17 * There are special exceptions to the terms and conditions of the GPL as 17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception 18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or 19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlife.com/developers/opensource/flossexception 20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 * 21 *
22 * By copying, modifying or distributing this software, you acknowledge 22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above, 23 * that you have read and understood your obligations described above,
@@ -246,6 +246,84 @@ LLWString utf16str_to_wstring(const llutf16string &utf16str)
246 return utf16str_to_wstring(utf16str, len); 246 return utf16str_to_wstring(utf16str, len);
247} 247}
248 248
249// Length in llwchar (UTF-32) of the first len units (16 bits) of the given UTF-16 string.
250S32 utf16str_wstring_length(const llutf16string &utf16str, const S32 utf16_len)
251{
252 S32 surrogate_pairs = 0;
253 // ... craziness to make gcc happy (llutf16string.c_str() is tweaked on linux):
254 const U16 *const utf16_chars = &(*(utf16str.begin()));
255 S32 i = 0;
256 while (i < utf16_len)
257 {
258 const U16 c = utf16_chars[i++];
259 if (c >= 0xD800 && c <= 0xDBFF) // See http://en.wikipedia.org/wiki/UTF-16
260 { // Have first byte of a surrogate pair
261 if (i >= utf16_len)
262 {
263 break;
264 }
265 const U16 d = utf16_chars[i];
266 if (d >= 0xDC00 && d <= 0xDFFF)
267 { // Have valid second byte of a surrogate pair
268 surrogate_pairs++;
269 i++;
270 }
271 }
272 }
273 return utf16_len - surrogate_pairs;
274}
275
276// Length in utf16string (UTF-16) of wlen wchars beginning at woffset.
277S32 wstring_utf16_length(const LLWString &wstr, const S32 woffset, const S32 wlen)
278{
279 const S32 end = llmin((S32)wstr.length(), woffset + wlen);
280 if (end < woffset)
281 {
282 return 0;
283 }
284 else
285 {
286 S32 length = end - woffset;
287 for (S32 i = woffset; i < end; i++)
288 {
289 if (wstr[i] >= 0x10000)
290 {
291 length++;
292 }
293 }
294 return length;
295 }
296}
297
298// Given a wstring and an offset in it, returns the length as wstring (i.e.,
299// number of llwchars) of the longest substring that starts at the offset
300// and whose equivalent utf-16 string does not exceeds the given utf16_length.
301S32 wstring_wstring_length_from_utf16_length(const LLWString & wstr, const S32 woffset, const S32 utf16_length, BOOL *unaligned)
302{
303 const S32 end = wstr.length();
304 BOOL u = FALSE;
305 S32 n = woffset + utf16_length;
306 S32 i = woffset;
307 while (i < end)
308 {
309 if (wstr[i] >= 0x10000)
310 {
311 --n;
312 }
313 if (i >= n)
314 {
315 u = (i > n);
316 break;
317 }
318 i++;
319 }
320 if (unaligned)
321 {
322 *unaligned = u;
323 }
324 return i - woffset;
325}
326
249S32 wchar_utf8_length(const llwchar wc) 327S32 wchar_utf8_length(const llwchar wc)
250{ 328{
251 if (wc < 0x80) 329 if (wc < 0x80)