michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1997-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * file name: cpputils.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: */ michael@0: michael@0: #ifndef CPPUTILS_H michael@0: #define CPPUTILS_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/unistr.h" michael@0: #include "cmemory.h" michael@0: michael@0: /*==========================================================================*/ michael@0: /* Array copy utility functions */ michael@0: /*==========================================================================*/ michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const double* src, double* dst, int32_t count) michael@0: { uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const double* src, int32_t srcStart, michael@0: double* dst, int32_t dstStart, int32_t count) michael@0: { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const int8_t* src, int8_t* dst, int32_t count) michael@0: { uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const int8_t* src, int32_t srcStart, michael@0: int8_t* dst, int32_t dstStart, int32_t count) michael@0: { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const int16_t* src, int16_t* dst, int32_t count) michael@0: { uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const int16_t* src, int32_t srcStart, michael@0: int16_t* dst, int32_t dstStart, int32_t count) michael@0: { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const int32_t* src, int32_t* dst, int32_t count) michael@0: { uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void uprv_arrayCopy(const int32_t* src, int32_t srcStart, michael@0: int32_t* dst, int32_t dstStart, int32_t count) michael@0: { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); } michael@0: michael@0: static michael@0: inline void michael@0: uprv_arrayCopy(const UChar *src, int32_t srcStart, michael@0: UChar *dst, int32_t dstStart, int32_t count) michael@0: { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); } michael@0: michael@0: /** michael@0: * Copy an array of UnicodeString OBJECTS (not pointers). michael@0: * @internal michael@0: */ michael@0: static inline void michael@0: uprv_arrayCopy(const icu::UnicodeString *src, icu::UnicodeString *dst, int32_t count) michael@0: { while(count-- > 0) *dst++ = *src++; } michael@0: michael@0: /** michael@0: * Copy an array of UnicodeString OBJECTS (not pointers). michael@0: * @internal michael@0: */ michael@0: static inline void michael@0: uprv_arrayCopy(const icu::UnicodeString *src, int32_t srcStart, michael@0: icu::UnicodeString *dst, int32_t dstStart, int32_t count) michael@0: { uprv_arrayCopy(src+srcStart, dst+dstStart, count); } michael@0: michael@0: /** michael@0: * Checks that the string is readable and writable. michael@0: * Sets U_ILLEGAL_ARGUMENT_ERROR if the string isBogus() or has an open getBuffer(). michael@0: */ michael@0: inline void michael@0: uprv_checkCanGetBuffer(const icu::UnicodeString &s, UErrorCode &errorCode) { michael@0: if(U_SUCCESS(errorCode) && s.isBogus()) { michael@0: errorCode=U_ILLEGAL_ARGUMENT_ERROR; michael@0: } michael@0: } michael@0: michael@0: #endif /* _CPPUTILS */