summaryrefslogtreecommitdiffstats
path: root/intl/icu/source/tools/genrb/ustr.h
blob: 8a69e9d4d5cb98351becaec36164625d85436fa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
*
*   Copyright (C) 1998-2012, International Business Machines
*   Corporation and others.  All Rights Reserved.
*
*******************************************************************************
*
* File ustr.h
*
* Modification History:
*
*   Date        Name        Description
*   05/28/99    stephen     Creation.
*******************************************************************************
*/

#ifndef USTR_H
#define USTR_H 1

#include "unicode/utypes.h"

#define U_APPEND_CHAR32(c,target,len) UPRV_BLOCK_MACRO_BEGIN {  \
    if (c <= 0xffff)                                            \
    {                                                           \
        *(target)++ = (UChar) c;                                \
        len=1;                                                  \
    }                                                           \
    else                                                        \
    {                                                           \
        target[0] = U16_LEAD(c);                                \
        target[1] = U16_TRAIL(c);                               \
        len=2;                                                  \
        target +=2;                                             \
    }                                                           \
} UPRV_BLOCK_MACRO_END

#define U_APPEND_CHAR32_ONLY(c,target) UPRV_BLOCK_MACRO_BEGIN { \
    if (c <= 0xffff)                                            \
    {                                                           \
        *(target)++ = (UChar) c;                                \
    }                                                           \
    else                                                        \
    {                                                           \
        target[0] = U16_LEAD(c);                                \
        target[1] = U16_TRAIL(c);                               \
        target +=2;                                             \
    }                                                           \
} UPRV_BLOCK_MACRO_END

/* A C representation of a string "object" (to avoid realloc all the time) */
struct UString {
  UChar *fChars;
  int32_t fLength;
  int32_t fCapacity;
};

U_CFUNC void ustr_init(struct UString *s);

U_CFUNC void
ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode *status);

U_CFUNC void ustr_deinit(struct UString *s);

U_CFUNC void ustr_setlen(struct UString *s, int32_t len, UErrorCode *status);

U_CFUNC void ustr_cpy(struct UString *dst, const struct UString *src,
                      UErrorCode *status);

U_CFUNC void ustr_cat(struct UString *dst, const struct UString *src,
                      UErrorCode *status);

U_CFUNC void ustr_ncat(struct UString *dst, const struct UString *src,
                       int32_t n, UErrorCode *status);

U_CFUNC void ustr_ucat(struct UString *dst, UChar c, UErrorCode *status);
U_CFUNC void ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status);
U_CFUNC void ustr_uscat(struct UString *dst, const UChar* src,int len,UErrorCode *status);
#endif