intl/icu/source/common/cpputils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/cpputils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/*
     1.5 +******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1997-2011, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +******************************************************************************
    1.11 +*   file name:  cpputils.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*/
    1.16 +
    1.17 +#ifndef CPPUTILS_H
    1.18 +#define CPPUTILS_H
    1.19 +
    1.20 +#include "unicode/utypes.h"
    1.21 +#include "unicode/unistr.h"
    1.22 +#include "cmemory.h"
    1.23 +
    1.24 +/*==========================================================================*/
    1.25 +/* Array copy utility functions */
    1.26 +/*==========================================================================*/
    1.27 +
    1.28 +static
    1.29 +inline void uprv_arrayCopy(const double* src, double* dst, int32_t count)
    1.30 +{ uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
    1.31 +
    1.32 +static
    1.33 +inline void uprv_arrayCopy(const double* src, int32_t srcStart,
    1.34 +              double* dst, int32_t dstStart, int32_t count)
    1.35 +{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
    1.36 +
    1.37 +static
    1.38 +inline void uprv_arrayCopy(const int8_t* src, int8_t* dst, int32_t count)
    1.39 +    { uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
    1.40 +
    1.41 +static
    1.42 +inline void uprv_arrayCopy(const int8_t* src, int32_t srcStart,
    1.43 +              int8_t* dst, int32_t dstStart, int32_t count)
    1.44 +{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
    1.45 +
    1.46 +static
    1.47 +inline void uprv_arrayCopy(const int16_t* src, int16_t* dst, int32_t count)
    1.48 +{ uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
    1.49 +
    1.50 +static
    1.51 +inline void uprv_arrayCopy(const int16_t* src, int32_t srcStart,
    1.52 +              int16_t* dst, int32_t dstStart, int32_t count)
    1.53 +{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
    1.54 +
    1.55 +static
    1.56 +inline void uprv_arrayCopy(const int32_t* src, int32_t* dst, int32_t count)
    1.57 +{ uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
    1.58 +
    1.59 +static
    1.60 +inline void uprv_arrayCopy(const int32_t* src, int32_t srcStart,
    1.61 +              int32_t* dst, int32_t dstStart, int32_t count)
    1.62 +{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
    1.63 +
    1.64 +static
    1.65 +inline void
    1.66 +uprv_arrayCopy(const UChar *src, int32_t srcStart,
    1.67 +        UChar *dst, int32_t dstStart, int32_t count)
    1.68 +{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
    1.69 +
    1.70 +/**
    1.71 + * Copy an array of UnicodeString OBJECTS (not pointers).
    1.72 + * @internal
    1.73 + */
    1.74 +static inline void
    1.75 +uprv_arrayCopy(const icu::UnicodeString *src, icu::UnicodeString *dst, int32_t count)
    1.76 +{ while(count-- > 0) *dst++ = *src++; }
    1.77 +
    1.78 +/**
    1.79 + * Copy an array of UnicodeString OBJECTS (not pointers).
    1.80 + * @internal
    1.81 + */
    1.82 +static inline void
    1.83 +uprv_arrayCopy(const icu::UnicodeString *src, int32_t srcStart,
    1.84 +               icu::UnicodeString *dst, int32_t dstStart, int32_t count)
    1.85 +{ uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
    1.86 +
    1.87 +/**
    1.88 + * Checks that the string is readable and writable.
    1.89 + * Sets U_ILLEGAL_ARGUMENT_ERROR if the string isBogus() or has an open getBuffer().
    1.90 + */
    1.91 +inline void
    1.92 +uprv_checkCanGetBuffer(const icu::UnicodeString &s, UErrorCode &errorCode) {
    1.93 +    if(U_SUCCESS(errorCode) && s.isBogus()) {
    1.94 +        errorCode=U_ILLEGAL_ARGUMENT_ERROR;
    1.95 +    }
    1.96 +}
    1.97 +
    1.98 +#endif /* _CPPUTILS */

mercurial