1219019Sgabor/* Internal function for converting integers to ASCII. 2219019Sgabor Copyright (C) 1994,95,96,97,98,99,2002,2003 Free Software Foundation, Inc. 3219019Sgabor This file is part of the GNU C Library. 4219019Sgabor 5219019Sgabor The GNU C Library is free software; you can redistribute it and/or 6219019Sgabor modify it under the terms of the GNU Lesser General Public 7219019Sgabor License as published by the Free Software Foundation; either 8219019Sgabor version 2.1 of the License, or (at your option) any later version. 9219019Sgabor 10219019Sgabor The GNU C Library is distributed in the hope that it will be useful, 11219019Sgabor but WITHOUT ANY WARRANTY; without even the implied warranty of 12219019Sgabor MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13219019Sgabor Lesser General Public License for more details. 14219019Sgabor 15219019Sgabor You should have received a copy of the GNU Lesser General Public 16219019Sgabor License along with the GNU C Library; if not, write to the Free 17219019Sgabor Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18219019Sgabor 02111-1307 USA. */ 19219019Sgabor 20219019Sgabor#ifndef _ITOWA_H 21219019Sgabor#define _ITOWA_H 1 22219019Sgabor 23219019Sgabor/* Convert VALUE into ASCII in base BASE (2..16). 24219019Sgabor Write backwards starting the character just before BUFLIM. 25219019Sgabor Return the address of the first (left-to-right) character in the number. 26219019Sgabor Use upper case letters iff UPPER_CASE is nonzero. */ 27219019Sgabor 28219019Sgaborstatic const wchar_t _itowa_lower_digits[16] = L_("0123456789abcdef"); 29219019Sgaborstatic const wchar_t _itowa_upper_digits[16] = L_("0123456789ABCDEF"); 30219019Sgabor 31219019Sgaborstatic inline wchar_t * 32219019Sgabor__attribute__ ((unused, always_inline)) 33219019Sgabor_itowa_word (unsigned long value, wchar_t *buflim, 34219019Sgabor unsigned int base, int upper_case) 35219019Sgabor{ 36219019Sgabor const wchar_t *digits = (upper_case 37219019Sgabor ? _itowa_upper_digits : _itowa_lower_digits); 38219019Sgabor wchar_t *bp = buflim; 39219019Sgabor 40219019Sgabor switch (base) 41219019Sgabor { 42219019Sgabor#define SPECIAL(Base) \ 43219019Sgabor case Base: \ 44219019Sgabor do \ 45219019Sgabor *--bp = digits[value % Base]; \ 46219019Sgabor while ((value /= Base) != 0); \ 47219019Sgabor break 48219019Sgabor 49219019Sgabor SPECIAL (10); 50219019Sgabor SPECIAL (16); 51219019Sgabor SPECIAL (8); 52219019Sgabor default: 53219019Sgabor do 54219019Sgabor *--bp = digits[value % base]; 55219019Sgabor while ((value /= base) != 0); 56219019Sgabor } 57219019Sgabor return bp; 58219019Sgabor} 59219019Sgabor 60219019Sgaborstatic inline wchar_t * 61219019Sgabor__attribute__ ((unused, always_inline)) 62219019Sgabor_itowa (uint64_t value, wchar_t *buflim, 63219019Sgabor unsigned int base, int upper_case) 64219019Sgabor{ 65219019Sgabor const wchar_t *digits = (upper_case 66219019Sgabor ? _itowa_upper_digits : _itowa_lower_digits); 67219019Sgabor wchar_t *bp = buflim; 68219019Sgabor 69219019Sgabor switch (base) 70219019Sgabor { 71219019Sgabor SPECIAL (10); 72219019Sgabor SPECIAL (16); 73219019Sgabor SPECIAL (8); 74219019Sgabor default: 75219019Sgabor do 76219019Sgabor *--bp = digits[value % base]; 77219019Sgabor while ((value /= base) != 0); 78219019Sgabor } 79219019Sgabor return bp; 80219019Sgabor} 81219019Sgabor#undef SPECIAL 82219019Sgabor 83219019Sgabor#endif /* itowa.h */ 84219019Sgabor