/*
*******************************************************************************
*
-* Copyright (C) 2002-2009, International Business Machines
+* Copyright (C) 2002-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
*
*******************************************************************************
*/
+
+// Safer use of UnicodeString.
+#ifndef UNISTR_FROM_CHAR_EXPLICIT
+# define UNISTR_FROM_CHAR_EXPLICIT explicit
+#endif
+
+// Less important, but still a good idea.
+#ifndef UNISTR_FROM_STRING_EXPLICIT
+# define UNISTR_FROM_STRING_EXPLICIT explicit
+#endif
+
#include "reslist.h"
#include "unewdata.h"
#include "unicode/ures.h"
#include "unicode/ucnv.h"
#include "genrb.h"
#include "rle.h"
-#include "ucol_tok.h"
#include "uhash.h"
#include "uresimp.h"
#include "unicode/ustring.h"
#include "ustr.h"
#include "prscmnts.h"
#include "unicode/unistr.h"
+#include "unicode/utf8.h"
+#include "unicode/utf16.h"
#include <time.h>
U_NAMESPACE_USE
* conversion is not portable across platforms with different endianess.
*/
-uint32_t computeCRC(char *ptr, uint32_t len, uint32_t lastcrc){
+uint32_t computeCRC(const char *ptr, uint32_t len, uint32_t lastcrc){
int32_t crc;
uint32_t temp1;
uint32_t temp2;
return NULL;
}
- if((destLen+UTF8_CHAR_LENGTH(c)) < destCap){
+ if((destLen+U8_LENGTH(c)) < destCap){
/* ASCII Range */
if(c <=0x007F){
}
}
static void
-printNoteElements(struct UString *src, UErrorCode *status){
+printNoteElements(const UString *src, UErrorCode *status){
#if UCONFIG_NO_REGULAR_EXPRESSIONS==0 /* donot compile when no RegularExpressions are available */
uprv_free(trans);
return;
}
+ // TODO: make src const, stop modifying it in-place, make printContainer() take const resource, etc.
src->fLength = removeCmtText(src->fChars, src->fLength, status);
descLen = getDescription(src->fChars,src->fLength, &desc, capacity, status);
transLen = getTranslate(src->fChars,src->fLength, &trans, capacity, status);
* <trans-unit id = "blah" resname = "blah" restype = "x-id-alias" translate = "no">
* <group id "calendar_gregorian" resname = "gregorian" restype = "x-icu-array">
*/
-static char *printContainer(struct SResource *res, const char *container, const char *restype, const char *mimetype, const char *id, UErrorCode *status)
+static char *printContainer(SResource *res, const char *container, const char *restype, const char *mimetype, const char *id, UErrorCode *status)
{
- char resKeyBuffer[8];
const char *resname = NULL;
char *sid = NULL;
write_tabs(out);
- resname = res_getKeyString(srBundle, res, resKeyBuffer);
+ resname = res->getKeyString(srBundle);
if (resname != NULL && *resname != 0) {
sid = getID(id, resname, sid);
} else {
static const char *table_restype = "x-icu-table";
static void
-string_write_xml(struct SResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
+string_write_xml(StringResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
char *sid = NULL;
char* buf = NULL;
write_utf8_file(out, UnicodeString(source));
- buf = convertAndEscape(&buf, 0, &bufLen, res->u.fString.fChars, res->u.fString.fLength, status);
+ buf = convertAndEscape(&buf, 0, &bufLen, res->getBuffer(), res->length(), status);
if (U_FAILURE(*status)) {
return;
}
static void
-alias_write_xml(struct SResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
+alias_write_xml(AliasResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
char *sid = NULL;
char* buf = NULL;
int32_t bufLen=0;
write_utf8_file(out, UnicodeString(source));
- buf = convertAndEscape(&buf, 0, &bufLen, res->u.fString.fChars, res->u.fString.fLength, status);
+ buf = convertAndEscape(&buf, 0, &bufLen, res->getBuffer(), res->length(), status);
if(U_FAILURE(*status)){
return;
}
static void
-array_write_xml(struct SResource *res, const char* id, const char* language, UErrorCode *status) {
+array_write_xml(ArrayResource *res, const char* id, const char* language, UErrorCode *status) {
char* sid = NULL;
int index = 0;
struct SResource *current = NULL;
- struct SResource *first =NULL;
sid = printContainer(res, group, array_restype, NULL, id, status);
- current = res->u.fArray.fFirst;
- first=current;
+ current = res->fFirst;
while (current != NULL) {
char c[256] = {0};
}
static void
-intvector_write_xml(struct SResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
+intvector_write_xml(IntVectorResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
char* sid = NULL;
char* ivd = NULL;
uint32_t i=0;
sid = printContainer(res, group, intvector_restype, NULL, id, status);
- for(i = 0; i < res->u.fIntVector.fCount; i += 1) {
+ for(i = 0; i < res->fCount; i += 1) {
char c[256] = {0};
itostr(c, i, 10, 0);
ivd = getID(sid, c, ivd);
- len = itostr(buf, res->u.fIntVector.fArray[i], 10, 0);
+ len = itostr(buf, res->fArray[i], 10, 0);
write_tabs(out);
write_utf8_file(out, UnicodeString("<"));
}
static void
-int_write_xml(struct SResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
+int_write_xml(IntResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
char* sid = NULL;
char buf[256] = {0};
uint32_t len = 0;
write_utf8_file(out, UnicodeString(source));
- len = itostr(buf, res->u.fIntValue.fValue, 10, 0);
+ len = itostr(buf, res->fValue, 10, 0);
write_utf8_file(out, UnicodeString(buf, len));
write_utf8_file(out, UnicodeString(close_source));
}
static void
-bin_write_xml(struct SResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
+bin_write_xml(BinaryResource *res, const char* id, const char* /*language*/, UErrorCode *status) {
const char* m_type = application_mimetype;
char* sid = NULL;
uint32_t crc = 0xFFFFFFFF;
char fileName[1024] ={0};
int32_t tLen = ( outDir == NULL) ? 0 :(int32_t)uprv_strlen(outDir);
char* fn = (char*) uprv_malloc(sizeof(char) * (tLen+1024 +
- (res->u.fBinaryValue.fFileName !=NULL ?
- uprv_strlen(res->u.fBinaryValue.fFileName) :0)));
+ (res->fFileName !=NULL ?
+ uprv_strlen(res->fFileName) :0)));
const char* ext = NULL;
char* f = NULL;
fn[0]=0;
- if(res->u.fBinaryValue.fFileName != NULL){
- uprv_strcpy(fileName, res->u.fBinaryValue.fFileName);
+ if(res->fFileName != NULL){
+ uprv_strcpy(fileName, res->fFileName);
f = uprv_strrchr(fileName, '\\');
if (f != NULL) {
write_utf8_file(out, UnicodeString(internal_file));
printAttribute("form", application_mimetype, (int32_t) uprv_strlen(application_mimetype));
- while(i <res->u.fBinaryValue.fLength){
- len = itostr(temp, res->u.fBinaryValue.fData[i], 16, 2);
+ while(i <res->fLength){
+ len = itostr(temp, res->fData[i], 16, 2);
crc = computeCRC(temp, len, crc);
i++;
}
write_utf8_file(out, UnicodeString(">"));
i = 0;
- while(i <res->u.fBinaryValue.fLength){
- len = itostr(temp, res->u.fBinaryValue.fData[i], 16, 2);
+ while(i <res->fLength){
+ len = itostr(temp, res->fData[i], 16, 2);
write_utf8_file(out, UnicodeString(temp));
i += 1;
}
static void
-table_write_xml(struct SResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status) {
+table_write_xml(TableResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status) {
uint32_t i = 0;
struct SResource *current = NULL;
- struct SResource *save = NULL;
char* sid = NULL;
if (U_FAILURE(*status)) {
sid[0] = '\0';
}
- save = current = res->u.fTable.fFirst;
+ current = res->fFirst;
i = 0;
while (current != NULL) {
if (res != NULL) {
switch (res->fType) {
case URES_STRING:
- string_write_xml (res, id, language, status);
+ string_write_xml (static_cast<StringResource *>(res), id, language, status);
return;
case URES_ALIAS:
- alias_write_xml (res, id, language, status);
+ alias_write_xml (static_cast<AliasResource *>(res), id, language, status);
return;
case URES_INT_VECTOR:
- intvector_write_xml (res, id, language, status);
+ intvector_write_xml (static_cast<IntVectorResource *>(res), id, language, status);
return;
case URES_BINARY:
- bin_write_xml (res, id, language, status);
+ bin_write_xml (static_cast<BinaryResource *>(res), id, language, status);
return;
case URES_INT:
- int_write_xml (res, id, language, status);
+ int_write_xml (static_cast<IntResource *>(res), id, language, status);
return;
case URES_ARRAY:
- array_write_xml (res, id, language, status);
+ array_write_xml (static_cast<ArrayResource *>(res), id, language, status);
return;
case URES_TABLE:
- table_write_xml (res, id, language, isTopLevel, status);
+ table_write_xml (static_cast<TableResource *>(res), id, language, isTopLevel, status);
return;
default:
*status = U_FILE_ACCESS_ERROR;
goto cleanup_bundle_write_xml;
}
- write_utf8_file(out, xmlHeader);
+ write_utf8_file(out, UnicodeString(xmlHeader));
if(outputEnc && *outputEnc!='\0'){
/* store the output encoding */
goto cleanup_bundle_write_xml;
}
}
- write_utf8_file(out, bundleStart);
+ write_utf8_file(out, UnicodeString(bundleStart));
write_tabs(out);
- write_utf8_file(out, fileStart);
+ write_utf8_file(out, UnicodeString(fileStart));
/* check if lang and language are the same */
if(language != NULL && uprv_strcmp(lang, srBundle->fLocale)!=0){
fprintf(stderr,"Warning: The top level tag in the resource and language specified are not the same. Please check the input.\n");
tabCount += 1;
write_tabs(out);
- write_utf8_file(out, headerStart);
+ write_utf8_file(out, UnicodeString(headerStart));
tabCount += 1;
write_tabs(out);
- write_utf8_file(out, tool_start);
+ write_utf8_file(out, UnicodeString(tool_start));
printAttribute("tool-id", tool_id, (int32_t) uprv_strlen(tool_id));
printAttribute("tool-name", tool_name, (int32_t) uprv_strlen(tool_name));
write_utf8_file(out, UnicodeString("/>\n"));