Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (C) 2001-2006, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "cstring.h" |
michael@0 | 9 | #include "ustrfmt.h" |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | /*** |
michael@0 | 13 | * Fills in a UChar* string with the radix-based representation of a |
michael@0 | 14 | * uint32_t number padded with zeroes to minwidth. The result |
michael@0 | 15 | * will be null terminated if there is room. |
michael@0 | 16 | * |
michael@0 | 17 | * @param buffer UChar buffer to receive result |
michael@0 | 18 | * @param capacity capacity of buffer |
michael@0 | 19 | * @param i the unsigned number to be formatted |
michael@0 | 20 | * @param radix the radix from 2..36 |
michael@0 | 21 | * @param minwidth the minimum width. If the result is narrower than |
michael@0 | 22 | * this, '0's will be added on the left. Must be <= |
michael@0 | 23 | * capacity. |
michael@0 | 24 | * @return the length of the result, not including any terminating |
michael@0 | 25 | * null |
michael@0 | 26 | */ |
michael@0 | 27 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 28 | uprv_itou (UChar * buffer, int32_t capacity, |
michael@0 | 29 | uint32_t i, uint32_t radix, int32_t minwidth) |
michael@0 | 30 | { |
michael@0 | 31 | int32_t length = 0; |
michael@0 | 32 | int digit; |
michael@0 | 33 | int32_t j; |
michael@0 | 34 | UChar temp; |
michael@0 | 35 | |
michael@0 | 36 | do{ |
michael@0 | 37 | digit = (int)(i % radix); |
michael@0 | 38 | buffer[length++]=(UChar)(digit<=9?(0x0030+digit):(0x0030+digit+7)); |
michael@0 | 39 | i=i/radix; |
michael@0 | 40 | } while(i && length<capacity); |
michael@0 | 41 | |
michael@0 | 42 | while (length < minwidth){ |
michael@0 | 43 | buffer[length++] = (UChar) 0x0030;/*zero padding */ |
michael@0 | 44 | } |
michael@0 | 45 | /* null terminate the buffer */ |
michael@0 | 46 | if(length<capacity){ |
michael@0 | 47 | buffer[length] = (UChar) 0x0000; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | /* Reverses the string */ |
michael@0 | 51 | for (j = 0; j < (length / 2); j++){ |
michael@0 | 52 | temp = buffer[(length-1) - j]; |
michael@0 | 53 | buffer[(length-1) - j] = buffer[j]; |
michael@0 | 54 | buffer[j] = temp; |
michael@0 | 55 | } |
michael@0 | 56 | return length; |
michael@0 | 57 | } |