diff options
Diffstat (limited to 'strings')
-rw-r--r-- | strings/int2str.c | 102 | ||||
-rw-r--r-- | strings/longlong2str-x86.s | 4 | ||||
-rw-r--r-- | strings/longlong2str.c | 10 | ||||
-rw-r--r-- | strings/my_vsnprintf.c | 2 |
4 files changed, 59 insertions, 59 deletions
diff --git a/strings/int2str.c b/strings/int2str.c index 38e8a5182a3..39b38ef3e1b 100644 --- a/strings/int2str.c +++ b/strings/int2str.c @@ -14,42 +14,50 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* - Defines: int2str(), itoa(), ltoa() - - int2str(dst, radix, val) - converts the (long) integer "val" to character form and moves it to - the destination string "dst" followed by a terminating NUL. The - result is normally a pointer to this NUL character, but if the radix - is dud the result will be NullS and nothing will be changed. - - If radix is -2..-36, val is taken to be SIGNED. - If radix is 2.. 36, val is taken to be UNSIGNED. - That is, val is signed if and only if radix is. You will normally - use radix -10 only through itoa and ltoa, for radix 2, 8, or 16 - unsigned is what you generally want. - - _dig_vec is public just in case someone has a use for it. - The definitions of itoa and ltoa are actually macros in m_string.h, - but this is where the code is. - - Note: The standard itoa() returns a pointer to the argument, when int2str - returns the pointer to the end-null. - itoa assumes that 10 -base numbers are allways signed and other arn't. -*/ - #include <my_global.h> #include "m_string.h" -char NEAR _dig_vec[] = +/* + _dig_vec arrays are public because they are used in several outer places. +*/ +char NEAR _dig_vec_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +char NEAR _dig_vec_lower[] = + "0123456789abcdefghijklmnopqrstuvwxyz"; -char *int2str(register long int val, register char *dst, register int radix) +/* + Convert integer to its string representation in given scale of notation. + + SYNOPSIS + int2str() + val - value to convert + dst - points to buffer where string representation should be stored + radix - radix of scale of notation + upcase - flag indicating that whenever we should use upper-case digits + + DESCRIPTION + Converts the (long) integer value to its character form and moves it to + the destination buffer followed by a terminating NUL. + If radix is -2..-36, val is taken to be SIGNED, if radix is 2..36, val is + taken to be UNSIGNED. That is, val is signed if and only if radix is. + All other radixes treated as bad and nothing will be changed in this case. + + For conversion to decimal representation (radix is -10 or 10) one can use + optimized int10_to_str() function. + + RETURN VALUE + Pointer to ending NUL character or NullS if radix is bad. +*/ + +char * +int2str(register long int val, register char *dst, register int radix, + char upcase) { char buffer[65]; register char *p; long int new_val; + char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower; if (radix < 0) { if (radix < -36 || radix > -2) return NullS; @@ -75,21 +83,21 @@ char *int2str(register long int val, register char *dst, register int radix) p = &buffer[sizeof(buffer)-1]; *p = '\0'; new_val=(ulong) val / (ulong) radix; - *--p = _dig_vec[(uchar) ((ulong) val- (ulong) new_val*(ulong) radix)]; + *--p = dig_vec[(uchar) ((ulong) val- (ulong) new_val*(ulong) radix)]; val = new_val; #ifdef HAVE_LDIV while (val != 0) { ldiv_t res; res=ldiv(val,radix); - *--p = _dig_vec[res.rem]; + *--p = dig_vec[res.rem]; val= res.quot; } #else while (val != 0) { new_val=val/radix; - *--p = _dig_vec[(uchar) (val-new_val*radix)]; + *--p = dig_vec[(uchar) (val-new_val*radix)]; val= new_val; } #endif @@ -99,8 +107,21 @@ char *int2str(register long int val, register char *dst, register int radix) /* - This is a faster version of the above optimized for the normal case of - radix 10 / -10 + Converts integer to its string representation in decimal notation. + + SYNOPSIS + int10_to_str() + val - value to convert + dst - points to buffer where string representation should be stored + radix - flag that shows whenever val should be taken as signed or not + + DESCRIPTION + This is version of int2str() function which is optimized for normal case + of radix 10/-10. It takes only sign of radix parameter into account and + not its absolute value. + + RETURN VALUE + Pointer to ending NUL character. */ char *int10_to_str(long int val,char *dst,int radix) @@ -133,22 +154,3 @@ char *int10_to_str(long int val,char *dst,int radix) while ((*dst++ = *p++) != 0) ; return dst-1; } - - -#ifdef USE_MY_ITOA - - /* Change to less general itoa interface */ - -char *my_itoa(int val, char *dst, int radix) -{ - VOID(int2str((long) val,dst,(radix == 10 ? -10 : radix))); - return dst; -} - -char *my_ltoa(long int val, char *dst, int radix) -{ - VOID(int2str((long) val,dst,(radix == 10 ? -10 : radix))); - return dst; -} - -#endif diff --git a/strings/longlong2str-x86.s b/strings/longlong2str-x86.s index 8476bf49b75..fcc57810224 100644 --- a/strings/longlong2str-x86.s +++ b/strings/longlong2str-x86.s @@ -83,7 +83,7 @@ longlong2str: divl %ebx decl %ecx movl %eax,%esi # quotent in ebp:esi - movb _dig_vec(%edx),%al # al is faster than dl + movb _dig_vec_upper(%edx),%al # al is faster than dl movb %al,(%ecx) # store value in buff .align 4 .L155: @@ -93,7 +93,7 @@ longlong2str: jl .L153 je .L10_mov # Ready movl %esi,%eax - movl $_dig_vec,%ebp + movl $_dig_vec_upper,%ebp .align 4 .L154: # Do rest with integer precision diff --git a/strings/longlong2str.c b/strings/longlong2str.c index a991c57b4d9..096531095db 100644 --- a/strings/longlong2str.c +++ b/strings/longlong2str.c @@ -43,8 +43,6 @@ #if defined(HAVE_LONG_LONG) && !defined(longlong2str) && !defined(HAVE_LONGLONG2STR) -extern char NEAR _dig_vec[]; - /* This assumes that longlong multiplication is faster than longlong division. */ @@ -81,14 +79,14 @@ char *longlong2str(longlong val,char *dst,int radix) { ulonglong quo=(ulonglong) val/(uint) radix; uint rem= (uint) (val- quo* (uint) radix); - *--p = _dig_vec[rem]; + *--p = _dig_vec_upper[rem]; val= quo; } long_val= (long) val; while (long_val != 0) { long quo= long_val/radix; - *--p = _dig_vec[(uchar) (long_val - quo*radix)]; + *--p = _dig_vec_upper[(uchar) (long_val - quo*radix)]; long_val= quo; } while ((*dst++ = *p++) != 0) ; @@ -126,14 +124,14 @@ char *longlong10_to_str(longlong val,char *dst,int radix) { ulonglong quo=(ulonglong) val/(uint) 10; uint rem= (uint) (val- quo* (uint) 10); - *--p = _dig_vec[rem]; + *--p = _dig_vec_upper[rem]; val= quo; } long_val= (long) val; while (long_val != 0) { long quo= long_val/10; - *--p = _dig_vec[(uchar) (long_val - quo*10)]; + *--p = _dig_vec_upper[(uchar) (long_val - quo*10)]; long_val= quo; } while ((*dst++ = *p++) != 0) ; diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c index d9d80263d31..dc03c130dcd 100644 --- a/strings/my_vsnprintf.c +++ b/strings/my_vsnprintf.c @@ -118,7 +118,7 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) if (*fmt== 'u') store_end= int10_to_str(larg, store_start, 10); else - store_end= int2str(larg, store_start, 16); + store_end= int2str(larg, store_start, 16, 0); if ((res_length= (uint) (store_end - store_start)) > to_length) break; /* num doesn't fit in output */ /* If %#d syntax was used, we have to pre-zero/pre-space the string */ |