comparison dwtx/dwtxhelper/mangoicu/UText.d @ 91:11e8159caf7a

make the mango icu fork work.
author Frank Benoit <benoit@tionex.de>
date Mon, 07 Jul 2008 15:53:07 +0200
parents
children
comparison
equal deleted inserted replaced
90:7ffeace6c47f 91:11e8159caf7a
1 /*******************************************************************************
2
3 @file UString.d
4
5 Copyright (c) 2008 Frank Benoit
6
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for damages
9 of any kind arising from the use of this software.
10
11 Permission is hereby granted to anyone to use this software for any
12 purpose, including commercial applications, and to alter it and/or
13 redistribute it freely, subject to the following restrictions:
14
15 1. The origin of this software must not be misrepresented; you must
16 not claim that you wrote the original software. If you use this
17 software in a product, an acknowledgment within documentation of
18 said product would be appreciated but is not required.
19
20 2. Altered source versions must be plainly marked as such, and must
21 not be misrepresented as being the original software.
22
23 3. This notice may not be removed or altered from any distribution
24 of the source.
25
26 4. Derivative works are permitted, but they must carry this notice
27 in full and credit the original source.
28
29
30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32
33 @version Initial version, July 2008
34 @author Frank
35
36 Note that this package and documentation is built around the ICU
37 project (http://oss.software.ibm.com/icu/). Below is the license
38 statement as specified by that software:
39
40
41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42
43
44 ICU License - ICU 1.8.1 and later
45
46 COPYRIGHT AND PERMISSION NOTICE
47
48 Copyright (c) 1995-2003 International Business Machines Corporation and
49 others.
50
51 All rights reserved.
52
53 Permission is hereby granted, free of charge, to any person obtaining a
54 copy of this software and associated documentation files (the
55 "Software"), to deal in the Software without restriction, including
56 without limitation the rights to use, copy, modify, merge, publish,
57 distribute, and/or sell copies of the Software, and to permit persons
58 to whom the Software is furnished to do so, provided that the above
59 copyright notice(s) and this permission notice appear in all copies of
60 the Software and that both the above copyright notice(s) and this
61 permission notice appear in supporting documentation.
62
63 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
64 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
66 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
68 INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
69 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
70 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
71 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
72
73 Except as contained in this notice, the name of a copyright holder
74 shall not be used in advertising or otherwise to promote the sale, use
75 or other dealings in this Software without prior written authorization
76 of the copyright holder.
77
78 ----------------------------------------------------------------------
79
80 All trademarks and registered trademarks mentioned herein are the
81 property of their respective owners.
82
83 *******************************************************************************/
84 module dwtx.dwtxhelper.mangoicu.UText;
85
86 import dwtx.dwtxhelper.mangoicu.ICU;
87
88 struct UText {
89 // UText private fields -- start
90 private {
91 uint magic = UTEXT_MAGIC;
92 int flags = 0;
93 int providerProperties = 0;
94 int sizeOfStruct = UText.sizeof;
95 long chunkNativeLimit = 0;
96 int extraSize = 0;
97 int nativeIndexingLimit = 0;
98 long chunkNativeStart = 0;
99 int chunkOffset = 0;
100 int chunkLength = 0;
101 wchar* chunkContents = null;
102 void* pFuncs = null;
103 void* pExtra = null;
104 void* context = null;
105 void* p = null;
106 void* q = null;
107 void* r = null;
108 void* privP = null;
109 long a = 0;
110 int b = 0;
111 int c = 0;
112 long privA = 0;
113 int privB = 0;
114 int privC = 0;
115 } // UText private fields -- end
116 // do not add any non-static fields
117
118 private enum {
119 UTEXT_MAGIC = 0x345ad82c
120 }
121 void close(){
122 utext_close(this);
123 }
124 private void ensureStatusOk( ICU.UErrorCode status ){
125 if( status !is ICU.UErrorCode.OK ){
126 throw new Exception( "ICU Exception" );
127 }
128 }
129 void openUTF8( char[] str ){
130 auto status = ICU.UErrorCode.OK;
131 utext_openUTF8(this, str.ptr, str.length, status );
132 ensureStatusOk( status );
133 }
134
135
136 /***********************************************************************
137
138 Bind the ICU functions from a shared library. This is
139 complicated by the issues regarding D and DLLs on the
140 Windows platform
141
142 ***********************************************************************/
143
144 private static void* library;
145
146 /***********************************************************************
147
148 ***********************************************************************/
149 static extern(System){
150 UText * function(UText* ut) utext_close;
151 UText * function(UText* ut, char *s, long length, inout ICU.UErrorCode status) utext_openUTF8;
152 // UText * function(UText* ut, UChar *s, int64_t length, inout UErrorCode status) utext_openUChars;
153 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER UnicodeString *s, inout UErrorCode status) utext_openUnicodeString;
154 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER UnicodeString *s, inout UErrorCode status) utext_openConstUnicodeString;
155 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER Replaceable *rep, inout UErrorCode status) utext_openReplaceable;
156 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER CharacterIterator *ic, inout UErrorCode status) utext_openCharacterIterator;
157 // UText * function(UText* ut, UText *src, UBool deep, UBool readOnly, inout UErrorCode status) utext_clone;
158 // UBool function(const UText *a, const UText *b) utext_equals;
159 // int64_t function(UText* ut) utext_nativeLength;
160 // UBool function(UText* ut) utext_isLengthExpensive;
161 // UChar32 function(UText* ut, int64_t nativeIndex) utext_char32At;
162 // UChar32 function(UText* ut) utext_current32;
163 // UChar32 function(UText* ut) utext_next32;
164 // UChar32 function(UText* ut) utext_previous32;
165 // UChar32 function(UText* ut, int64_t nativeIndex) utext_next32From;
166 // UChar32 function(UText* ut, int64_t nativeIndex) utext_previous32From;
167 // int64_t function(UText* ut) utext_getNativeIndex;
168 // void function(UText* ut, int64_t nativeIndex) utext_setNativeIndex;
169 // UBool function(UText* ut, int delta) utext_moveIndex32;
170 // int64_t function(UText* ut) utext_getPreviousNativeIndex;
171 // int function(UText* ut, int64_t nativeStart, int64_t nativeLimit,
172 // UChar *dest, int destCapacity,
173 // inout UErrorCode status) utext_extract;
174 // UBool function(UText* ut) utext_isWritable;
175 // UBool function(UText* ut) utext_hasMetaData;
176 // int function(UText* ut,
177 // int64_t nativeStart, int64_t nativeLimit,
178 // UChar *replacementText, int replacementLength,
179 // inout UErrorCode status) utext_replace;
180 // void function(UText* ut,
181 // int64_t nativeStart, int64_t nativeLimit,
182 // int64_t destIndex,
183 // UBool move,
184 // inout UErrorCode status) utext_copy;
185 // void function(UText* ut) utext_freeze;
186 // UText * function(UText* ut, int extraSpace, inout UErrorCode status) utext_setup;
187 }
188
189 /***********************************************************************
190
191 ***********************************************************************/
192 static FunctionLoader.Bind[] targets = [
193 {cast(void**) &utext_close, "utext_close"},
194 {cast(void**) &utext_openUTF8, "utext_openUTF8"},
195 // {cast(void**) &utext_openUChars, "utext_openUChars"},
196 // {cast(void**) &utext_openUnicodeString, "utext_openUnicodeString"},
197 // {cast(void**) &utext_openConstUnicodeString, "utext_openConstUnicodeString"},
198 // {cast(void**) &utext_openReplaceable, "utext_openReplaceable"},
199 // {cast(void**) &utext_openCharacterIterator, "utext_openCharacterIterator"},
200 // {cast(void**) &utext_clone, "utext_clone"},
201 // {cast(void**) &utext_equals, "utext_equals"},
202 // {cast(void**) &utext_nativeLength, "utext_nativeLength"},
203 // {cast(void**) &utext_isLengthExpensive, "utext_isLengthExpensive"},
204 // {cast(void**) &utext_char32At, "utext_char32At"},
205 // {cast(void**) &utext_current32, "utext_current32"},
206 // {cast(void**) &utext_next32, "utext_next32"},
207 // {cast(void**) &utext_next32From, "utext_next32From"},
208 // {cast(void**) &utext_previous32, "utext_previous32"},
209 // {cast(void**) &utext_previous32From, "utext_previous32From"},
210 // {cast(void**) &utext_setNativeIndex, "utext_setNativeIndex"},
211 // {cast(void**) &utext_moveIndex32, "utext_moveIndex32"},
212 // {cast(void**) &utext_getPreviousNativeIndex, "utext_getPreviousNativeIndex"},
213 // {cast(void**) &utext_extract, "utext_extract"},
214 // {cast(void**) &utext_isWritable, "utext_isWritable"},
215 // {cast(void**) &utext_hasMetaData, "utext_hasMetaData"},
216 // {cast(void**) &utext_replace, "utext_replace"},
217 // {cast(void**) &utext_copy, "utext_copy"},
218 // {cast(void**) &utext_freeze, "utext_freeze"},
219 // {cast(void**) &utext_setup, "utext_setup"},
220 ];
221
222 /***********************************************************************
223
224 ***********************************************************************/
225
226 static this ()
227 {
228 library = FunctionLoader.bind (ICU.icuuc, targets);
229 //test ();
230 }
231
232 /***********************************************************************
233
234 ***********************************************************************/
235
236 static ~this ()
237 {
238 FunctionLoader.unbind (library);
239 }
240
241 }