michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 2001-2006, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: */ michael@0: michael@0: #include "cstring.h" michael@0: #include "ustrfmt.h" michael@0: michael@0: michael@0: /*** michael@0: * Fills in a UChar* string with the radix-based representation of a michael@0: * uint32_t number padded with zeroes to minwidth. The result michael@0: * will be null terminated if there is room. michael@0: * michael@0: * @param buffer UChar buffer to receive result michael@0: * @param capacity capacity of buffer michael@0: * @param i the unsigned number to be formatted michael@0: * @param radix the radix from 2..36 michael@0: * @param minwidth the minimum width. If the result is narrower than michael@0: * this, '0's will be added on the left. Must be <= michael@0: * capacity. michael@0: * @return the length of the result, not including any terminating michael@0: * null michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uprv_itou (UChar * buffer, int32_t capacity, michael@0: uint32_t i, uint32_t radix, int32_t minwidth) michael@0: { michael@0: int32_t length = 0; michael@0: int digit; michael@0: int32_t j; michael@0: UChar temp; michael@0: michael@0: do{ michael@0: digit = (int)(i % radix); michael@0: buffer[length++]=(UChar)(digit<=9?(0x0030+digit):(0x0030+digit+7)); michael@0: i=i/radix; michael@0: } while(i && length