intl/icu/source/common/appendable.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2 *******************************************************************************
     3 *   Copyright (C) 2011-2012, International Business Machines
     4 *   Corporation and others.  All Rights Reserved.
     5 *******************************************************************************
     6 *   file name:  appendable.cpp
     7 *   encoding:   US-ASCII
     8 *   tab size:   8 (not used)
     9 *   indentation:4
    10 *
    11 *   created on: 2010dec07
    12 *   created by: Markus W. Scherer
    13 */
    15 #include "unicode/utypes.h"
    16 #include "unicode/appendable.h"
    17 #include "unicode/utf16.h"
    19 U_NAMESPACE_BEGIN
    21 Appendable::~Appendable() {}
    23 UBool
    24 Appendable::appendCodePoint(UChar32 c) {
    25     if(c<=0xffff) {
    26         return appendCodeUnit((UChar)c);
    27     } else {
    28         return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));
    29     }
    30 }
    32 UBool
    33 Appendable::appendString(const UChar *s, int32_t length) {
    34     if(length<0) {
    35         UChar c;
    36         while((c=*s++)!=0) {
    37             if(!appendCodeUnit(c)) {
    38                 return FALSE;
    39             }
    40         }
    41     } else if(length>0) {
    42         const UChar *limit=s+length;
    43         do {
    44             if(!appendCodeUnit(*s++)) {
    45                 return FALSE;
    46             }
    47         } while(s<limit);
    48     }
    49     return TRUE;
    50 }
    52 UBool
    53 Appendable::reserveAppendCapacity(int32_t /*appendCapacity*/) {
    54     return TRUE;
    55 }
    57 UChar *
    58 Appendable::getAppendBuffer(int32_t minCapacity,
    59                             int32_t /*desiredCapacityHint*/,
    60                             UChar *scratch, int32_t scratchCapacity,
    61                             int32_t *resultCapacity) {
    62     if(minCapacity<1 || scratchCapacity<minCapacity) {
    63         *resultCapacity=0;
    64         return NULL;
    65     }
    66     *resultCapacity=scratchCapacity;
    67     return scratch;
    68 }
    70 // UnicodeStringAppendable is implemented in unistr.cpp.
    72 U_NAMESPACE_END

mercurial