1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 2001-2006, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
15 * Fills in a UChar* string with the radix-based representation of a
16 * uint32_t number padded with zeroes to minwidth. The result
17 * will be null terminated if there is room.
19 * @param buffer UChar buffer to receive result
20 * @param capacity capacity of buffer
21 * @param i the unsigned number to be formatted
22 * @param radix the radix from 2..36
23 * @param minwidth the minimum width. If the result is narrower than
24 * this, '0's will be added on the left. Must be <=
26 * @return the length of the result, not including any terminating
29 U_CAPI int32_t U_EXPORT2
30 uprv_itou (UChar * buffer, int32_t capacity,
31 uint32_t i, uint32_t radix, int32_t minwidth)
39 digit = (int)(i % radix);
40 buffer[length++]=(UChar)(digit<=9?(0x0030+digit):(0x0030+digit+7));
42 } while(i && length<capacity);
44 while (length < minwidth){
45 buffer[length++] = (UChar) 0x0030;/*zero padding */
47 /* null terminate the buffer */
49 buffer[length] = (UChar) 0x0000;
52 /* Reverses the string */
53 for (j = 0; j < (length / 2); j++){
54 temp = buffer[(length-1) - j];
55 buffer[(length-1) - j] = buffer[j];