Index: source/tools/genrb/wrtjava.cpp |
diff --git a/source/tools/genrb/wrtjava.c b/source/tools/genrb/wrtjava.cpp |
similarity index 88% |
rename from source/tools/genrb/wrtjava.c |
rename to source/tools/genrb/wrtjava.cpp |
index 6239569d85e8939ccd8c6fe7642220108051c5e2..1788c8374feefaa1c63b2dc7edb06aa588b4f2be 100644 |
--- a/source/tools/genrb/wrtjava.c |
+++ b/source/tools/genrb/wrtjava.cpp |
@@ -1,12 +1,12 @@ |
/* |
******************************************************************************* |
* |
-* Copyright (C) 2000-2012, International Business Machines |
+* Copyright (C) 2000-2015, International Business Machines |
* Corporation and others. All Rights Reserved. |
* |
******************************************************************************* |
* |
-* File wrtjava.c |
+* File wrtjava.cpp |
* |
* Modification History: |
* |
@@ -18,6 +18,7 @@ |
*/ |
#include <assert.h> |
+#include "unicode/unistr.h" |
#include "reslist.h" |
#include "unewdata.h" |
#include "unicode/ures.h" |
@@ -100,7 +101,7 @@ static const char* enc =""; |
static UConverter* conv = NULL; |
static int32_t |
-uCharsToChars( char* target,int32_t targetLen, UChar* source, int32_t sourceLen,UErrorCode* status){ |
+uCharsToChars(char *target, int32_t targetLen, const UChar *source, int32_t sourceLen, UErrorCode *status) { |
int i=0, j=0; |
char str[30]={'\0'}; |
while(i<sourceLen){ |
@@ -225,7 +226,7 @@ static int32_t getColumnCount(int32_t len){ |
return columnCount; |
} |
static void |
-str_write_java( uint16_t* src, int32_t srcLen, UBool printEndLine, UErrorCode *status){ |
+str_write_java(const UChar *src, int32_t srcLen, UBool printEndLine, UErrorCode *status) { |
uint32_t length = srcLen*8; |
uint32_t bufLen = 0; |
@@ -304,23 +305,14 @@ str_write_java( uint16_t* src, int32_t srcLen, UBool printEndLine, UErrorCode *s |
/* Writing Functions */ |
static void |
-string_write_java(struct SResource *res,UErrorCode *status) { |
- char resKeyBuffer[8]; |
- const char *resname = res_getKeyString(srBundle, res, resKeyBuffer); |
- |
- str_write_java(res->u.fString.fChars,res->u.fString.fLength,TRUE,status); |
- |
- if(resname != NULL && uprv_strcmp(resname,"Rule")==0) |
- { |
- UChar* buf = (UChar*) uprv_malloc(sizeof(UChar)*res->u.fString.fLength); |
- uprv_memcpy(buf,res->u.fString.fChars,res->u.fString.fLength); |
- uprv_free(buf); |
- } |
+string_write_java(const StringResource *res,UErrorCode *status) { |
+ (void)res->getKeyString(srBundle); |
+ str_write_java(res->getBuffer(), res->length(), TRUE, status); |
} |
static void |
-array_write_java( struct SResource *res, UErrorCode *status) { |
+array_write_java(const ArrayResource *res, UErrorCode *status) { |
uint32_t i = 0; |
const char* arr ="new String[] { \n"; |
@@ -331,19 +323,19 @@ array_write_java( struct SResource *res, UErrorCode *status) { |
return; |
} |
- if (res->u.fArray.fCount > 0) { |
+ if (res->fCount > 0) { |
- current = res->u.fArray.fFirst; |
+ current = res->fFirst; |
i = 0; |
while(current != NULL){ |
- if(current->fType!=URES_STRING){ |
+ if(!current->isString()){ |
allStrings = FALSE; |
break; |
} |
current= current->fNext; |
} |
- current = res->u.fArray.fFirst; |
+ current = res->fFirst; |
if(allStrings==FALSE){ |
const char* object = "new Object[]{\n"; |
write_tabs(out); |
@@ -355,7 +347,7 @@ array_write_java( struct SResource *res, UErrorCode *status) { |
tabCount++; |
} |
while (current != NULL) { |
- /*if(current->fType==URES_STRING){ |
+ /*if(current->isString()){ |
write_tabs(out); |
}*/ |
res_write_java(current, status); |
@@ -380,13 +372,12 @@ array_write_java( struct SResource *res, UErrorCode *status) { |
} |
static void |
-intvector_write_java( struct SResource *res, UErrorCode *status) { |
+intvector_write_java(const IntVectorResource *res, UErrorCode * /*status*/) { |
uint32_t i = 0; |
const char* intArr = "new int[] {\n"; |
/* const char* intC = "new Integer("; */ |
const char* stringArr = "new String[]{\n"; |
- char resKeyBuffer[8]; |
- const char *resname = res_getKeyString(srBundle, res, resKeyBuffer); |
+ const char *resname = res->getKeyString(srBundle); |
char buf[100]; |
int len =0; |
buf[0]=0; |
@@ -395,9 +386,9 @@ intvector_write_java( struct SResource *res, UErrorCode *status) { |
if(resname != NULL && uprv_strcmp(resname,"DateTimeElements")==0){ |
T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr)); |
tabCount++; |
- for(i = 0; i<res->u.fIntVector.fCount; i++) { |
+ for(i = 0; i<res->fCount; i++) { |
write_tabs(out); |
- len=itostr(buf,res->u.fIntVector.fArray[i],10,0); |
+ len=itostr(buf,res->fArray[i],10,0); |
T_FileStream_write(out,"\"",1); |
T_FileStream_write(out,buf,len); |
T_FileStream_write(out,"\",",2); |
@@ -406,10 +397,10 @@ intvector_write_java( struct SResource *res, UErrorCode *status) { |
}else{ |
T_FileStream_write(out, intArr, (int32_t)uprv_strlen(intArr)); |
tabCount++; |
- for(i = 0; i<res->u.fIntVector.fCount; i++) { |
+ for(i = 0; i<res->fCount; i++) { |
write_tabs(out); |
/* T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); */ |
- len=itostr(buf,res->u.fIntVector.fArray[i],10,0); |
+ len=itostr(buf,res->fArray[i],10,0); |
T_FileStream_write(out,buf,len); |
/* T_FileStream_write(out,"),",2); */ |
/* T_FileStream_write(out,"\n",1); */ |
@@ -422,7 +413,7 @@ intvector_write_java( struct SResource *res, UErrorCode *status) { |
} |
static void |
-int_write_java(struct SResource *res,UErrorCode *status) { |
+int_write_java(const IntResource *res, UErrorCode * /*status*/) { |
const char* intC = "new Integer("; |
char buf[100]; |
int len =0; |
@@ -431,25 +422,25 @@ int_write_java(struct SResource *res,UErrorCode *status) { |
/* write the binary data */ |
write_tabs(out); |
T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); |
- len=itostr(buf, res->u.fIntValue.fValue, 10, 0); |
+ len=itostr(buf, res->fValue, 10, 0); |
T_FileStream_write(out,buf,len); |
T_FileStream_write(out,"),\n",3 ); |
} |
static void |
-bytes_write_java( struct SResource *res, UErrorCode *status) { |
+bytes_write_java(const BinaryResource *res, UErrorCode * /*status*/) { |
const char* type = "new byte[] {"; |
const char* byteDecl = "%i, "; |
char byteBuffer[100] = { 0 }; |
uint8_t* byteArray = NULL; |
int byteIterator = 0; |
- int32_t srcLen=res->u.fBinaryValue.fLength; |
+ int32_t srcLen=res->fLength; |
if(srcLen>0 ) |
{ |
- byteArray = res->u.fBinaryValue.fData; |
+ byteArray = res->fData; |
write_tabs(out); |
T_FileStream_write(out, type, (int32_t)uprv_strlen(type)); |
@@ -504,7 +495,7 @@ bytes_write_java( struct SResource *res, UErrorCode *status) { |
static UBool start = TRUE; |
static void |
-table_write_java(struct SResource *res, UErrorCode *status) { |
+table_write_java(const TableResource *res, UErrorCode *status) { |
uint32_t i = 0; |
struct SResource *current = NULL; |
const char* obj = "new Object[][]{\n"; |
@@ -513,22 +504,21 @@ table_write_java(struct SResource *res, UErrorCode *status) { |
return ; |
} |
- if (res->u.fTable.fCount > 0) { |
+ if (res->fCount > 0) { |
if(start==FALSE){ |
write_tabs(out); |
T_FileStream_write(out, obj, (int32_t)uprv_strlen(obj)); |
tabCount++; |
} |
start = FALSE; |
- current = res->u.fTable.fFirst; |
+ current = res->fFirst; |
i = 0; |
while (current != NULL) { |
- char currentKeyBuffer[8]; |
- const char *currentKeyString = res_getKeyString(srBundle, current, currentKeyBuffer); |
+ const char *currentKeyString = current->getKeyString(srBundle); |
- assert(i < res->u.fTable.fCount); |
+ assert(i < res->fCount); |
write_tabs(out); |
T_FileStream_write(out, openBrace, 2); |
@@ -582,26 +572,26 @@ res_write_java(struct SResource *res,UErrorCode *status) { |
if (res != NULL) { |
switch (res->fType) { |
case URES_STRING: |
- string_write_java (res, status); |
+ string_write_java (static_cast<const StringResource *>(res), status); |
return; |
case URES_ALIAS: |
printf("Encountered unsupported resource type %d of alias\n", res->fType); |
*status = U_UNSUPPORTED_ERROR; |
return; |
case URES_INT_VECTOR: |
- intvector_write_java (res, status); |
+ intvector_write_java (static_cast<const IntVectorResource *>(res), status); |
return; |
case URES_BINARY: |
- bytes_write_java (res, status); |
+ bytes_write_java (static_cast<const BinaryResource *>(res), status); |
return; |
case URES_INT: |
- int_write_java (res, status); |
+ int_write_java (static_cast<const IntResource *>(res), status); |
return; |
case URES_ARRAY: |
- array_write_java (res, status); |
+ array_write_java (static_cast<const ArrayResource *>(res), status); |
return; |
case URES_TABLE: |
- table_write_java (res, status); |
+ table_write_java (static_cast<const TableResource *>(res), status); |
return; |
default: |
break; |