Mercurial > projects > dwt2
comparison com.ibm.icu/src/com/ibm/icu/mangoicu/UString.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | ebefa5c2eab4 |
children |
comparison
equal
deleted
inserted
replaced
119:d00e8db0a568 | 120:536e43f63c81 |
---|---|
179 'mutable' parameter to false. Doing so will avoid allocating | 179 'mutable' parameter to false. Doing so will avoid allocating |
180 heap-space for the content until it is modified. | 180 heap-space for the content until it is modified. |
181 | 181 |
182 ***********************************************************************/ | 182 ***********************************************************************/ |
183 | 183 |
184 this (CString16 content, bool mutable = true) | 184 this (in wchar[] content, bool mutable = true) |
185 { | 185 { |
186 setTo (content, mutable); | 186 setTo (content, mutable); |
187 } | 187 } |
188 | 188 |
189 /*********************************************************************** | 189 /*********************************************************************** |
384 return opCat (&chr, 1); | 384 return opCat (&chr, 1); |
385 } | 385 } |
386 | 386 |
387 /*********************************************************************** | 387 /*********************************************************************** |
388 | 388 |
389 Append a single UTF32 unit to this UString | |
390 | |
391 ***********************************************************************/ | |
392 | |
393 UString opCat (dchar chr) | |
394 { | |
395 dchar[1] chars = chr; | |
396 return opCat (chars); | |
397 } | |
398 | |
399 /*********************************************************************** | |
400 | |
389 Append text to this UString | 401 Append text to this UString |
390 | 402 |
391 ***********************************************************************/ | 403 ***********************************************************************/ |
392 | 404 |
393 UString opCat (wchar[] chars) | 405 UString opCat (wchar[] chars) |
401 | 413 |
402 ***********************************************************************/ | 414 ***********************************************************************/ |
403 | 415 |
404 UString opCat (char[] chars) | 416 UString opCat (char[] chars) |
405 { | 417 { |
406 uint fmt (wchar* dst, uint len, inout UErrorCode e) | 418 uint fmt (wchar* dst, uint len, ref UErrorCode e) |
407 { | 419 { |
408 uint x; | 420 uint x; |
409 | 421 |
410 u_strFromUTF8 (dst, len, &x, chars.ptr, chars.length, e); | 422 u_strFromUTF8 (dst, len, &x, chars.ptr, chars.length, e); |
411 return x; | 423 return x; |
412 } | 424 } |
413 | 425 |
414 expand (chars.length); | 426 expand (chars.length); |
415 return format (&fmt, "failed to append UTF char[]"); | 427 return format (&fmt, "failed to append UTF char[]"); |
428 } | |
429 | |
430 /*********************************************************************** | |
431 | |
432 Converts a sequence of UTF32 units to UChars (UTF-16) | |
433 | |
434 ***********************************************************************/ | |
435 | |
436 UString opCat (dchar[] chars) | |
437 { | |
438 uint fmt (wchar* dst, uint len, ref UErrorCode e) | |
439 { | |
440 uint x; | |
441 | |
442 u_strFromUTF32 (dst, len, &x, chars.ptr, chars.length, e); | |
443 return x; | |
444 } | |
445 | |
446 expand (chars.length); | |
447 return format (&fmt, "failed to append UTF dchar[]"); | |
416 } | 448 } |
417 | 449 |
418 /*********************************************************************** | 450 /*********************************************************************** |
419 | 451 |
420 Set a section of this UString to the specified character | 452 Set a section of this UString to the specified character |
437 not, the array is aliased until such time this UString is | 469 not, the array is aliased until such time this UString is |
438 altered. | 470 altered. |
439 | 471 |
440 ***********************************************************************/ | 472 ***********************************************************************/ |
441 | 473 |
442 UString setTo (CString16 chars, bool mutable = true) | 474 UString setTo (in wchar[] chars, bool mutable = true) |
443 { | 475 { |
444 len = chars.length; | 476 len = chars.length; |
445 if ((this.mutable = mutable) == true) | 477 if ((this.mutable = mutable) == true) |
446 content = chars.dup; | 478 content = chars.dup; |
447 else | 479 else |
619 This is used by many of the ICU wrappers to append content | 651 This is used by many of the ICU wrappers to append content |
620 into a UString. | 652 into a UString. |
621 | 653 |
622 ***********************************************************************/ | 654 ***********************************************************************/ |
623 | 655 |
624 typedef uint delegate (wchar* dst, uint len, inout UErrorCode e) Formatter; | 656 typedef uint delegate (wchar* dst, uint len, ref UErrorCode e) Formatter; |
625 | 657 |
626 package final UString format (Formatter format, CString msg) | 658 package final UString format (Formatter format, String msg) |
627 { | 659 { |
628 UErrorCode e; | 660 UErrorCode e; |
629 uint length; | 661 uint length; |
630 | 662 |
631 while (true) | 663 while (true) |
1099 Note that the return value refers to the provided destination | 1131 Note that the return value refers to the provided destination |
1100 UString. | 1132 UString. |
1101 | 1133 |
1102 ***********************************************************************/ | 1134 ***********************************************************************/ |
1103 | 1135 |
1104 final UString toLower (UString dst, inout ULocale locale) | 1136 final UString toLower (UString dst, ref ULocale locale) |
1105 { | 1137 { |
1106 uint lower (wchar* dst, uint length, inout UErrorCode e) | 1138 uint lower (wchar* dst, uint length, ref UErrorCode e) |
1107 { | 1139 { |
1108 return u_strToLower (dst, length, content.ptr, len, ICU.toString(locale.name), e); | 1140 return u_strToLower (dst, length, content.ptr, len, ICU.toString(locale.name), e); |
1109 } | 1141 } |
1110 | 1142 |
1111 dst.expand (len + 32); | 1143 dst.expand (len + 32); |
1139 Note that the return value refers to the provided destination | 1171 Note that the return value refers to the provided destination |
1140 UString. | 1172 UString. |
1141 | 1173 |
1142 ***********************************************************************/ | 1174 ***********************************************************************/ |
1143 | 1175 |
1144 final UString toUpper (UString dst, inout ULocale locale) | 1176 final UString toUpper (UString dst, ref ULocale locale) |
1145 { | 1177 { |
1146 uint upper (wchar* dst, uint length, inout UErrorCode e) | 1178 uint upper (wchar* dst, uint length, ref UErrorCode e) |
1147 { | 1179 { |
1148 return u_strToUpper (dst, length, content.ptr, len, ICU.toString(locale.name), e); | 1180 return u_strToUpper (dst, length, content.ptr, len, ICU.toString(locale.name), e); |
1149 } | 1181 } |
1150 | 1182 |
1151 dst.expand (len + 32); | 1183 dst.expand (len + 32); |
1167 | 1199 |
1168 ***********************************************************************/ | 1200 ***********************************************************************/ |
1169 | 1201 |
1170 final UString toFolded (UString dst, CaseOption option = CaseOption.Default) | 1202 final UString toFolded (UString dst, CaseOption option = CaseOption.Default) |
1171 { | 1203 { |
1172 uint fold (wchar* dst, uint length, inout UErrorCode e) | 1204 uint fold (wchar* dst, uint length, ref UErrorCode e) |
1173 { | 1205 { |
1174 return u_strFoldCase (dst, length, content.ptr, len, option, e); | 1206 return u_strFoldCase (dst, length, content.ptr, len, option, e); |
1175 } | 1207 } |
1176 | 1208 |
1177 dst.expand (len + 32); | 1209 dst.expand (len + 32); |
1379 | 1411 |
1380 Pin the given index to a valid position. | 1412 Pin the given index to a valid position. |
1381 | 1413 |
1382 ***********************************************************************/ | 1414 ***********************************************************************/ |
1383 | 1415 |
1384 final private void pinIndex (inout uint x) | 1416 final private void pinIndex (ref uint x) |
1385 { | 1417 { |
1386 if (x > len) | 1418 if (x > len) |
1387 x = len; | 1419 x = len; |
1388 } | 1420 } |
1389 | 1421 |
1391 | 1423 |
1392 Pin the given index and length to a valid position. | 1424 Pin the given index and length to a valid position. |
1393 | 1425 |
1394 ***********************************************************************/ | 1426 ***********************************************************************/ |
1395 | 1427 |
1396 final private void pinIndices (inout uint start, inout uint length) | 1428 final private void pinIndices (ref uint start, ref uint length) |
1397 { | 1429 { |
1398 if (start > len) | 1430 if (start > len) |
1399 start = len; | 1431 start = len; |
1400 | 1432 |
1401 if (length > (len - start)) | 1433 if (length > (len - start)) |
1424 complicated by the issues regarding D and DLLs on the | 1456 complicated by the issues regarding D and DLLs on the |
1425 Windows platform | 1457 Windows platform |
1426 | 1458 |
1427 ***********************************************************************/ | 1459 ***********************************************************************/ |
1428 | 1460 |
1429 private static void* library; | 1461 mixin(genICUNative!("uc" |
1430 | 1462 ,"wchar* function (wchar*, uint, wchar*, uint)", "u_strFindFirst" |
1431 /*********************************************************************** | 1463 ,"wchar* function (wchar*, uint, wchar*, uint)", "u_strFindLast" |
1432 | 1464 ,"wchar* function (wchar*, wchar, uint)", "u_memchr" |
1433 ***********************************************************************/ | 1465 ,"wchar* function (wchar*, wchar, uint)", "u_memrchr" |
1434 | 1466 ,"int function (wchar*, uint, wchar*, uint, bool)", "u_strCompare" |
1435 private static extern (C) | 1467 ,"int function (wchar*, uint, wchar*, uint, uint, ref UErrorCode)", "u_strCaseCompare" |
1436 { | 1468 ,"dchar function (CharAt, uint*, uint, void*)", "u_unescapeAt" |
1437 wchar* function (wchar*, uint, wchar*, uint) u_strFindFirst; | 1469 ,"uint function (wchar*, uint)", "u_countChar32" |
1438 wchar* function (wchar*, uint, wchar*, uint) u_strFindLast; | 1470 ,"uint function (wchar*, uint, wchar*, uint, char*, ref UErrorCode)", "u_strToUpper" |
1439 wchar* function (wchar*, wchar, uint) u_memchr; | 1471 ,"uint function (wchar*, uint, wchar*, uint, char*, ref UErrorCode)", "u_strToLower" |
1440 wchar* function (wchar*, wchar, uint) u_memrchr; | 1472 ,"uint function (wchar*, uint, wchar*, uint, uint, ref UErrorCode)", "u_strFoldCase" |
1441 int function (wchar*, uint, wchar*, uint, bool) u_strCompare; | 1473 ,"wchar* function (wchar*, uint, uint*, char*, uint, ref UErrorCode)", "u_strFromUTF8" |
1442 int function (wchar*, uint, wchar*, uint, uint, inout UErrorCode) u_strCaseCompare; | 1474 ,"wchar* function (wchar*, uint, uint*, dchar*, uint, ref UErrorCode)", "u_strFromUTF32" |
1443 dchar function (CharAt, uint*, uint, void*) u_unescapeAt; | 1475 ,"char* function (char*, uint, uint*, wchar*, uint, ref UErrorCode)", "u_strToUTF8" |
1444 uint function (wchar*, uint) u_countChar32; | 1476 )); |
1445 uint function (wchar*, uint, wchar*, uint, char*, inout UErrorCode) u_strToUpper; | |
1446 uint function (wchar*, uint, wchar*, uint, char*, inout UErrorCode) u_strToLower; | |
1447 uint function (wchar*, uint, wchar*, uint, uint, inout UErrorCode) u_strFoldCase; | |
1448 wchar* function (wchar*, uint, uint*, char*, uint, inout UErrorCode) u_strFromUTF8; | |
1449 char* function (char*, uint, uint*, wchar*, uint, inout UErrorCode) u_strToUTF8; | |
1450 } | |
1451 | |
1452 /*********************************************************************** | |
1453 | |
1454 ***********************************************************************/ | |
1455 | |
1456 static FunctionLoader.Bind[] targets = | |
1457 [ | |
1458 {cast(void**) &u_strFindFirst, "u_strFindFirst"}, | |
1459 {cast(void**) &u_strFindLast, "u_strFindLast"}, | |
1460 {cast(void**) &u_memchr, "u_memchr"}, | |
1461 {cast(void**) &u_memrchr, "u_memrchr"}, | |
1462 {cast(void**) &u_strCompare, "u_strCompare"}, | |
1463 {cast(void**) &u_strCaseCompare, "u_strCaseCompare"}, | |
1464 {cast(void**) &u_unescapeAt, "u_unescapeAt"}, | |
1465 {cast(void**) &u_countChar32, "u_countChar32"}, | |
1466 {cast(void**) &u_strToUpper, "u_strToUpper"}, | |
1467 {cast(void**) &u_strToLower, "u_strToLower"}, | |
1468 {cast(void**) &u_strFoldCase, "u_strFoldCase"}, | |
1469 {cast(void**) &u_strFromUTF8, "u_strFromUTF8"}, | |
1470 {cast(void**) &u_strToUTF8, "u_strToUTF8"}, | |
1471 ]; | |
1472 | |
1473 /*********************************************************************** | |
1474 | |
1475 ***********************************************************************/ | |
1476 | |
1477 static this () | |
1478 { | |
1479 library = FunctionLoader.bind (icuuc, targets); | |
1480 //test (); | |
1481 } | |
1482 | |
1483 /*********************************************************************** | |
1484 | |
1485 ***********************************************************************/ | |
1486 | |
1487 static ~this () | |
1488 { | |
1489 FunctionLoader.unbind (library); | |
1490 } | |
1491 | 1477 |
1492 /*********************************************************************** | 1478 /*********************************************************************** |
1493 | 1479 |
1494 ***********************************************************************/ | 1480 ***********************************************************************/ |
1495 | 1481 |
1496 //private static void test() | 1482 //private static void test() |
1497 //{ | 1483 //{ |
1498 // UString s = new UString (r"aaaqw \uabcd eaaa"); | 1484 // UString s = new UString (r"aaaqw \uabcd eaaa"); |
1499 // CString16 x = "dssfsdff"; | 1485 // const String16 x = "dssfsdff"; |
1500 // s ~ x ~ x; | 1486 // s ~ x ~ x; |
1501 // wchar c = s[3]; | 1487 // wchar c = s[3]; |
1502 // s[3] = 'Q'; | 1488 // s[3] = 'Q'; |
1503 // int y = s.indexOf ("qwe"); | 1489 // int y = s.indexOf ("qwe"); |
1504 // s.unEscape (); | 1490 // s.unEscape (); |