]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ustrfmt.c
2 **********************************************************************
3 * Copyright (C) 2001-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
13 * Fills in a UChar* string with the radix-based representation of a
14 * uint32_t number padded with zeroes to minwidth. The result
15 * will be null terminated if there is room.
17 * @param buffer UChar buffer to receive result
18 * @param capacity capacity of buffer
19 * @param i the unsigned number to be formatted
20 * @param radix the radix from 2..36
21 * @param minwidth the minimum width. If the result is narrower than
22 * this, '0's will be added on the left. Must be <=
24 * @return the length of the result, not including any terminating
27 U_CAPI
int32_t U_EXPORT2
28 uprv_itou (UChar
* buffer
, int32_t capacity
,
29 uint32_t i
, uint32_t radix
, int32_t minwidth
)
37 digit
= (int)(i
% radix
);
38 buffer
[length
++]=(UChar
)(digit
<=9?(0x0030+digit
):(0x0030+digit
+7));
40 } while(i
&& length
<capacity
);
42 while (length
< minwidth
){
43 buffer
[length
++] = (UChar
) 0x0030;/*zero padding */
45 /* null terminate the buffer */
47 buffer
[length
] = (UChar
) 0x0000;
50 /* Reverses the string */
51 for (j
= 0; j
< (length
/ 2); j
++){
52 temp
= buffer
[(length
-1) - j
];
53 buffer
[(length
-1) - j
] = buffer
[j
];