comparison com.ibm.icu/src/com/ibm/icu/mangoicu/UCollator.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
86 86
87 private import com.ibm.icu.mangoicu.ICU, 87 private import com.ibm.icu.mangoicu.ICU,
88 com.ibm.icu.mangoicu.USet, 88 com.ibm.icu.mangoicu.USet,
89 com.ibm.icu.mangoicu.ULocale, 89 com.ibm.icu.mangoicu.ULocale,
90 com.ibm.icu.mangoicu.UString; 90 com.ibm.icu.mangoicu.UString;
91 private import java.lang.util;
91 92
92 /******************************************************************************* 93 /*******************************************************************************
93 94
94 The API for Collator performs locale-sensitive string comparison. 95 The API for Collator performs locale-sensitive string comparison.
95 You use this service to build searching and sorting routines for 96 You use this service to build searching and sorting routines for
348 349
349 ***********************************************************************/ 350 ***********************************************************************/
350 351
351 void getDisplayName (ULocale obj, ULocale display, UString dst) 352 void getDisplayName (ULocale obj, ULocale display, UString dst)
352 { 353 {
353 uint fmt (wchar* p, uint len, inout UErrorCode e) 354 uint fmt (wchar* p, uint len, ref UErrorCode e)
354 { 355 {
355 return ucol_getDisplayName (toString(obj.name), toString(display.name), dst.get.ptr, dst.len, e); 356 return ucol_getDisplayName (toString(obj.name), toString(display.name), dst.get.ptr, dst.len, e);
356 } 357 }
357 358
358 dst.format (&fmt, "failed to get collator display name"); 359 dst.format (&fmt, "failed to get collator display name");
365 366
366 ***********************************************************************/ 367 ***********************************************************************/
367 368
368 void getRules (UString dst, RuleOption o = RuleOption.FullRules) 369 void getRules (UString dst, RuleOption o = RuleOption.FullRules)
369 { 370 {
370 uint fmt (wchar* p, uint len, inout UErrorCode e) 371 uint fmt (wchar* p, uint len, ref UErrorCode e)
371 { 372 {
372 uint needed = ucol_getRulesEx (handle, o, dst.get.ptr, dst.len); 373 uint needed = ucol_getRulesEx (handle, o, dst.get.ptr, dst.len);
373 if (needed > len) 374 if (needed > len)
374 e = e.BufferOverflow; 375 e = e.BufferOverflow;
375 return needed; 376 return needed;
501 among other things, on major versions of the collator 502 among other things, on major versions of the collator
502 tailoring and UCA 503 tailoring and UCA
503 504
504 ***********************************************************************/ 505 ***********************************************************************/
505 506
506 void getVersion (inout Version v) 507 void getVersion (ref Version v)
507 { 508 {
508 ucol_getVersion (handle, v); 509 ucol_getVersion (handle, v);
509 } 510 }
510 511
511 /*********************************************************************** 512 /***********************************************************************
512 513
513 Gets the UCA version information for this Collator 514 Gets the UCA version information for this Collator
514 515
515 ***********************************************************************/ 516 ***********************************************************************/
516 517
517 void getUCAVersion (inout Version v) 518 void getUCAVersion (ref Version v)
518 { 519 {
519 ucol_getUCAVersion (handle, v); 520 ucol_getUCAVersion (handle, v);
520 } 521 }
521 522
522 /*********************************************************************** 523 /***********************************************************************
607 608
608 void getLocale (ULocale locale, ULocale.Type type) 609 void getLocale (ULocale locale, ULocale.Type type)
609 { 610 {
610 UErrorCode e; 611 UErrorCode e;
611 612
612 locale.name = toArray (ucol_getLocaleByType (handle, type, e)); 613 locale.name = cast(String) toArray (ucol_getLocaleByType (handle, type, e));
613 if (isError(e) || locale.name is null) 614 if (isError(e) || locale.name is null)
614 exception ("failed to get collator locale"); 615 exception ("failed to get collator locale");
615 } 616 }
616 617
617 /*********************************************************************** 618 /***********************************************************************
637 complicated by the issues regarding D and DLLs on the 638 complicated by the issues regarding D and DLLs on the
638 Windows platform 639 Windows platform
639 640
640 ***********************************************************************/ 641 ***********************************************************************/
641 642
642 private static void* library; 643 mixin(genICUNative!("in"
643 644 ,"void function (Handle)", "ucol_close"
644 /*********************************************************************** 645 ,"Handle function (char *loc, ref UErrorCode e)", "ucol_open"
645 646 ,"Handle function (wchar* rules, uint rulesLength, AttributeValue normalizationMode, Strength strength, UParseError *parseError, ref UErrorCode e)", "ucol_openRules"
646 ***********************************************************************/ 647 ,"Handle function (char *definition, byte forceDefaults, UParseError *parseError, ref UErrorCode e)", "ucol_openFromShortString"
647 648 ,"uint function (Handle, Handle conts, ref UErrorCode e)", "ucol_getContractions"
648 private static extern (C) 649 ,"int function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength)", "ucol_strcoll"
649 { 650 ,"byte function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength)", "ucol_greater"
650 void function (Handle) ucol_close; 651 ,"byte function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength)", "ucol_greaterOrEqual"
651 Handle function (char *loc, inout UErrorCode e) ucol_open; 652 ,"byte function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength)", "ucol_equal"
652 Handle function (wchar* rules, uint rulesLength, AttributeValue normalizationMode, Strength strength, UParseError *parseError, inout UErrorCode e) ucol_openRules; 653 ,"Strength function (Handle)", "ucol_getStrength"
653 Handle function (char *definition, byte forceDefaults, UParseError *parseError, inout UErrorCode e) ucol_openFromShortString; 654 ,"void function (Handle, Strength strength)", "ucol_setStrength"
654 uint function (Handle, Handle conts, inout UErrorCode e) ucol_getContractions; 655 ,"uint function (char *objLoc, char *dispLoc, wchar* result, uint resultLength, ref UErrorCode e)", "ucol_getDisplayName"
655 int function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength) ucol_strcoll; 656 ,"uint function (Handle, char *locale, char *buffer, uint capacity, ref UErrorCode e)", "ucol_getShortDefinitionString"
656 byte function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength) ucol_greater; 657 ,"uint function (char *source, char *destination, uint capacity, UParseError *parseError, ref UErrorCode e)", "ucol_normalizeShortDefinitionString"
657 byte function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength) ucol_greaterOrEqual; 658 ,"uint function (Handle, wchar* source, uint sourceLength, ubyte *result, uint resultLength)", "ucol_getSortKey"
658 byte function (Handle, wchar* source, uint sourceLength, wchar* target, uint targetLength) ucol_equal; 659 ,"uint function (ubyte *source, uint sourceLength, BoundMode boundType, uint noOfLevels, ubyte *result, uint resultLength, ref UErrorCode e)", "ucol_getBound"
659 Strength function (Handle) ucol_getStrength; 660 ,"void function (Handle, Version info)", "ucol_getVersion"
660 void function (Handle, Strength strength) ucol_setStrength; 661 ,"void function (Handle, Version info)", "ucol_getUCAVersion"
661 uint function (char *objLoc, char *dispLoc, wchar* result, uint resultLength, inout UErrorCode e) ucol_getDisplayName; 662 ,"uint function (ubyte *src1, uint src1Length, ubyte *src2, uint src2Length, ubyte *dest, uint destCapacity)", "ucol_mergeSortkeys"
662 uint function (Handle, char *locale, char *buffer, uint capacity, inout UErrorCode e) ucol_getShortDefinitionString; 663 ,"void function (Handle, Attribute attr, AttributeValue value, ref UErrorCode e)", "ucol_setAttribute"
663 uint function (char *source, char *destination, uint capacity, UParseError *parseError, inout UErrorCode e) ucol_normalizeShortDefinitionString; 664 ,"AttributeValue function (Handle, Attribute attr, ref UErrorCode e)", "ucol_getAttribute"
664 uint function (Handle, wchar* source, uint sourceLength, ubyte *result, uint resultLength) ucol_getSortKey; 665 ,"uint function (Handle, wchar* varTop, uint len, ref UErrorCode e)", "ucol_setVariableTop"
665 uint function (ubyte *source, uint sourceLength, BoundMode boundType, uint noOfLevels, ubyte *result, uint resultLength, inout UErrorCode e) ucol_getBound; 666 ,"uint function (Handle, ref UErrorCode e)", "ucol_getVariableTop"
666 void function (Handle, Version info) ucol_getVersion; 667 ,"void function (Handle, uint varTop, ref UErrorCode e)", "ucol_restoreVariableTop"
667 void function (Handle, Version info) ucol_getUCAVersion; 668 ,"uint function (Handle, RuleOption delta, wchar* buffer, uint bufferLen)", "ucol_getRulesEx"
668 uint function (ubyte *src1, uint src1Length, ubyte *src2, uint src2Length, ubyte *dest, uint destCapacity) ucol_mergeSortkeys; 669 ,"char* function (Handle, ULocale.Type type, ref UErrorCode e)", "ucol_getLocaleByType"
669 void function (Handle, Attribute attr, AttributeValue value, inout UErrorCode e) ucol_setAttribute; 670 ,"Handle function (Handle, ref UErrorCode e)", "ucol_getTailoredSet"
670 AttributeValue function (Handle, Attribute attr, inout UErrorCode e) ucol_getAttribute; 671 ));
671 uint function (Handle, wchar* varTop, uint len, inout UErrorCode e) ucol_setVariableTop;
672 uint function (Handle, inout UErrorCode e) ucol_getVariableTop;
673 void function (Handle, uint varTop, inout UErrorCode e) ucol_restoreVariableTop;
674 uint function (Handle, RuleOption delta, wchar* buffer, uint bufferLen) ucol_getRulesEx;
675 char* function (Handle, ULocale.Type type, inout UErrorCode e) ucol_getLocaleByType;
676 Handle function (Handle, inout UErrorCode e) ucol_getTailoredSet;
677 }
678
679 /***********************************************************************
680
681 ***********************************************************************/
682
683 static FunctionLoader.Bind[] targets =
684 [
685 {cast(void**) &ucol_open, "ucol_open"},
686 {cast(void**) &ucol_close, "ucol_close"},
687 {cast(void**) &ucol_openRules, "ucol_openRules"},
688 {cast(void**) &ucol_openFromShortString, "ucol_openFromShortString"},
689 {cast(void**) &ucol_getContractions, "ucol_getContractions"},
690 {cast(void**) &ucol_strcoll, "ucol_strcoll"},
691 {cast(void**) &ucol_greater, "ucol_greater"},
692 {cast(void**) &ucol_greaterOrEqual, "ucol_greaterOrEqual"},
693 {cast(void**) &ucol_equal, "ucol_equal"},
694 {cast(void**) &ucol_getStrength, "ucol_getStrength"},
695 {cast(void**) &ucol_setStrength, "ucol_setStrength"},
696 {cast(void**) &ucol_getDisplayName, "ucol_getDisplayName"},
697 {cast(void**) &ucol_getShortDefinitionString, "ucol_getShortDefinitionString"},
698 {cast(void**) &ucol_normalizeShortDefinitionString, "ucol_normalizeShortDefinitionString"},
699 {cast(void**) &ucol_getSortKey, "ucol_getSortKey"},
700 {cast(void**) &ucol_getBound, "ucol_getBound"},
701 {cast(void**) &ucol_getVersion, "ucol_getVersion"},
702 {cast(void**) &ucol_getUCAVersion, "ucol_getUCAVersion"},
703 {cast(void**) &ucol_mergeSortkeys, "ucol_mergeSortkeys"},
704 {cast(void**) &ucol_setAttribute, "ucol_setAttribute"},
705 {cast(void**) &ucol_getAttribute, "ucol_getAttribute"},
706 {cast(void**) &ucol_setVariableTop, "ucol_setVariableTop"},
707 {cast(void**) &ucol_getVariableTop, "ucol_getVariableTop"},
708 {cast(void**) &ucol_restoreVariableTop, "ucol_restoreVariableTop"},
709 {cast(void**) &ucol_getRulesEx, "ucol_getRulesEx"},
710 {cast(void**) &ucol_getLocaleByType, "ucol_getLocaleByType"},
711 {cast(void**) &ucol_getTailoredSet, "ucol_getTailoredSet"},
712 ];
713
714 /***********************************************************************
715
716 ***********************************************************************/
717
718 static this ()
719 {
720 library = FunctionLoader.bind (icuin, targets);
721 }
722
723 /***********************************************************************
724
725 ***********************************************************************/
726
727 static ~this ()
728 {
729 FunctionLoader.unbind (library);
730 }
731 } 672 }
732 673