X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..5ea0322b6ab2af986e4c764284141380031dd014:/icuSources/tools/genrb/ustr.c diff --git a/icuSources/tools/genrb/ustr.c b/icuSources/tools/genrb/ustr.c index 93c268e5..0f4f6793 100644 --- a/icuSources/tools/genrb/ustr.c +++ b/icuSources/tools/genrb/ustr.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2000, International Business Machines +* Copyright (C) 1998-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -19,6 +19,8 @@ #include "cmemory.h" #include "cstring.h" #include "unicode/ustring.h" +#include "unicode/putil.h" +#include "unicode/utf16.h" /* Protos */ static void ustr_resize(struct UString *s, int32_t len, UErrorCode *status); @@ -26,14 +28,14 @@ static void ustr_resize(struct UString *s, int32_t len, UErrorCode *status); /* Macros */ #define ALLOCATION(minSize) (minSize < 0x80 ? 0x80 : (2 * minSize + 0x80) & ~(0x80 - 1)) -void +U_CFUNC void ustr_init(struct UString *s) { s->fChars = 0; s->fLength = s->fCapacity = 0; } -void +U_CFUNC void ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode *status) { int i = 0; @@ -64,15 +66,17 @@ ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode } } -void +U_CFUNC void ustr_deinit(struct UString *s) { - uprv_free(s->fChars); - s->fChars = 0; - s->fLength = s->fCapacity = 0; + if (s) { + uprv_free(s->fChars); + s->fChars = 0; + s->fLength = s->fCapacity = 0; + } } -void +U_CFUNC void ustr_cpy(struct UString *dst, const struct UString *src, UErrorCode *status) @@ -85,13 +89,15 @@ ustr_cpy(struct UString *dst, if(U_FAILURE(*status)) return; } - - uprv_memcpy(dst->fChars, src->fChars, sizeof(UChar) * src->fLength); + if(src->fChars == NULL || dst->fChars == NULL){ + return; + } + u_memcpy(dst->fChars, src->fChars, src->fLength); dst->fLength = src->fLength; dst->fChars[dst->fLength] = 0x0000; } -void +U_CFUNC void ustr_setlen(struct UString *s, int32_t len, UErrorCode *status) @@ -109,7 +115,7 @@ ustr_setlen(struct UString *s, s->fChars[len] = 0x0000; } -void +U_CFUNC void ustr_cat(struct UString *dst, const struct UString *src, UErrorCode *status) @@ -117,7 +123,7 @@ ustr_cat(struct UString *dst, ustr_ncat(dst, src, src->fLength, status); } -void +U_CFUNC void ustr_ncat(struct UString *dst, const struct UString *src, int32_t n, @@ -138,7 +144,7 @@ ustr_ncat(struct UString *dst, dst->fChars[dst->fLength] = 0x0000; } -void +U_CFUNC void ustr_ucat(struct UString *dst, UChar c, UErrorCode *status) @@ -157,8 +163,20 @@ ustr_ucat(struct UString *dst, dst->fLength += 1; dst->fChars[dst->fLength] = 0x0000; } - -void +U_CFUNC void +ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status){ + if(c > 0x10FFFF){ + *status = U_ILLEGAL_CHAR_FOUND; + return; + } + if(c >0xFFFF){ + ustr_ucat(dst, U16_LEAD(c), status); + ustr_ucat(dst, U16_TRAIL(c), status); + }else{ + ustr_ucat(dst, (UChar) c, status); + } +} +U_CFUNC void ustr_uscat(struct UString *dst, const UChar* src,int len, UErrorCode *status) @@ -191,7 +209,6 @@ ustr_resize(struct UString *s, s->fChars = (UChar*) uprv_realloc(s->fChars, sizeof(UChar) * (len + 1)); if(s->fChars == 0) { *status = U_MEMORY_ALLOCATION_ERROR; - s->fChars = 0; s->fLength = s->fCapacity = 0; return; }