comparison com.ibm.icu/src/com/ibm/icu/mangoicu/UText.d @ 92:ebefa5c2eab4

moving ICU bindings to com.ibm.icu
author Frank Benoit <benoit@tionex.de>
date Sun, 19 Apr 2009 13:49:38 +0200
parents base/src/java/mangoicu/UText.d@1bf55a6eb092
children 536e43f63c81
comparison
equal deleted inserted replaced
91:2755ef2c8ef8 92:ebefa5c2eab4
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 com.ibm.icu.mangoicu.UText;
85
86 import com.ibm.icu.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 version(D_Version2){
123 utext_close(&this);
124 } else {
125 utext_close(this);
126 }
127 }
128 private void ensureStatusOk( ICU.UErrorCode status ){
129 if( status !is ICU.UErrorCode.OK ){
130 throw new Exception( "ICU Exception" );
131 }
132 }
133 void openUTF8( char[] str ){
134 auto status = ICU.UErrorCode.OK;
135 version(D_Version2){
136 utext_openUTF8(&this, str.ptr, str.length, status );
137 } else {
138 utext_openUTF8(this, str.ptr, str.length, status );
139 }
140 ensureStatusOk( status );
141 }
142
143
144 /***********************************************************************
145
146 Bind the ICU functions from a shared library. This is
147 complicated by the issues regarding D and DLLs on the
148 Windows platform
149
150 ***********************************************************************/
151
152 private static void* library;
153
154 /***********************************************************************
155
156 ***********************************************************************/
157 static extern(System){
158 UText * function(UText* ut) utext_close;
159 UText * function(UText* ut, char *s, long length, inout ICU.UErrorCode status) utext_openUTF8;
160 // UText * function(UText* ut, UChar *s, int64_t length, inout UErrorCode status) utext_openUChars;
161 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER UnicodeString *s, inout UErrorCode status) utext_openUnicodeString;
162 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER UnicodeString *s, inout UErrorCode status) utext_openConstUnicodeString;
163 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER Replaceable *rep, inout UErrorCode status) utext_openReplaceable;
164 // UText * function(UText* ut, U_NAMESPACE_QUALIFIER CharacterIterator *ic, inout UErrorCode status) utext_openCharacterIterator;
165 // UText * function(UText* ut, UText *src, UBool deep, UBool readOnly, inout UErrorCode status) utext_clone;
166 // UBool function(const UText *a, const UText *b) utext_equals;
167 // int64_t function(UText* ut) utext_nativeLength;
168 // UBool function(UText* ut) utext_isLengthExpensive;
169 // UChar32 function(UText* ut, int64_t nativeIndex) utext_char32At;
170 // UChar32 function(UText* ut) utext_current32;
171 // UChar32 function(UText* ut) utext_next32;
172 // UChar32 function(UText* ut) utext_previous32;
173 // UChar32 function(UText* ut, int64_t nativeIndex) utext_next32From;
174 // UChar32 function(UText* ut, int64_t nativeIndex) utext_previous32From;
175 // int64_t function(UText* ut) utext_getNativeIndex;
176 // void function(UText* ut, int64_t nativeIndex) utext_setNativeIndex;
177 // UBool function(UText* ut, int delta) utext_moveIndex32;
178 // int64_t function(UText* ut) utext_getPreviousNativeIndex;
179 // int function(UText* ut, int64_t nativeStart, int64_t nativeLimit,
180 // UChar *dest, int destCapacity,
181 // inout UErrorCode status) utext_extract;
182 // UBool function(UText* ut) utext_isWritable;
183 // UBool function(UText* ut) utext_hasMetaData;
184 // int function(UText* ut,
185 // int64_t nativeStart, int64_t nativeLimit,
186 // UChar *replacementText, int replacementLength,
187 // inout UErrorCode status) utext_replace;
188 // void function(UText* ut,
189 // int64_t nativeStart, int64_t nativeLimit,
190 // int64_t destIndex,
191 // UBool move,
192 // inout UErrorCode status) utext_copy;
193 // void function(UText* ut) utext_freeze;
194 // UText * function(UText* ut, int extraSpace, inout UErrorCode status) utext_setup;
195 }
196
197 /***********************************************************************
198
199 ***********************************************************************/
200 static FunctionLoader.Bind[] targets = [
201 {cast(void**) &utext_close, "utext_close"},
202 {cast(void**) &utext_openUTF8, "utext_openUTF8"},
203 // {cast(void**) &utext_openUChars, "utext_openUChars"},
204 // {cast(void**) &utext_openUnicodeString, "utext_openUnicodeString"},
205 // {cast(void**) &utext_openConstUnicodeString, "utext_openConstUnicodeString"},
206 // {cast(void**) &utext_openReplaceable, "utext_openReplaceable"},
207 // {cast(void**) &utext_openCharacterIterator, "utext_openCharacterIterator"},
208 // {cast(void**) &utext_clone, "utext_clone"},
209 // {cast(void**) &utext_equals, "utext_equals"},
210 // {cast(void**) &utext_nativeLength, "utext_nativeLength"},
211 // {cast(void**) &utext_isLengthExpensive, "utext_isLengthExpensive"},
212 // {cast(void**) &utext_char32At, "utext_char32At"},
213 // {cast(void**) &utext_current32, "utext_current32"},
214 // {cast(void**) &utext_next32, "utext_next32"},
215 // {cast(void**) &utext_next32From, "utext_next32From"},
216 // {cast(void**) &utext_previous32, "utext_previous32"},
217 // {cast(void**) &utext_previous32From, "utext_previous32From"},
218 // {cast(void**) &utext_setNativeIndex, "utext_setNativeIndex"},
219 // {cast(void**) &utext_moveIndex32, "utext_moveIndex32"},
220 // {cast(void**) &utext_getPreviousNativeIndex, "utext_getPreviousNativeIndex"},
221 // {cast(void**) &utext_extract, "utext_extract"},
222 // {cast(void**) &utext_isWritable, "utext_isWritable"},
223 // {cast(void**) &utext_hasMetaData, "utext_hasMetaData"},
224 // {cast(void**) &utext_replace, "utext_replace"},
225 // {cast(void**) &utext_copy, "utext_copy"},
226 // {cast(void**) &utext_freeze, "utext_freeze"},
227 // {cast(void**) &utext_setup, "utext_setup"},
228 ];
229
230 /***********************************************************************
231
232 ***********************************************************************/
233
234 static this ()
235 {
236 library = FunctionLoader.bind (ICU.icuuc, targets);
237 //test ();
238 }
239
240 /***********************************************************************
241
242 ***********************************************************************/
243
244 static ~this ()
245 {
246 FunctionLoader.unbind (library);
247 }
248
249 }