1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
16 |
#include "config.h" |
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
17 |
#include "drizzled/internal/m_string.h" |
1
by brian
clean slate |
18 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
19 |
namespace drizzled |
20 |
{
|
|
21 |
namespace internal |
|
22 |
{
|
|
1
by brian
clean slate |
23 |
|
24 |
/*
|
|
25 |
Converts integer to its string representation in decimal notation.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
26 |
|
1
by brian
clean slate |
27 |
SYNOPSIS
|
28 |
int10_to_str()
|
|
29 |
val - value to convert
|
|
30 |
dst - points to buffer where string representation should be stored
|
|
31 |
radix - flag that shows whenever val should be taken as signed or not
|
|
32 |
||
33 |
DESCRIPTION
|
|
34 |
This is version of int2str() function which is optimized for normal case
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
35 |
of radix 10/-10. It takes only sign of radix parameter into account and
|
1
by brian
clean slate |
36 |
not its absolute value.
|
37 |
||
38 |
RETURN VALUE
|
|
39 |
Pointer to ending NUL character.
|
|
40 |
*/
|
|
41 |
||
492.1.9
by Monty
Fixed problem on 32-bit. |
42 |
char *int10_to_str(int32_t val,char *dst,int radix) |
1
by brian
clean slate |
43 |
{
|
44 |
char buffer[65]; |
|
45 |
register char *p; |
|
492.1.9
by Monty
Fixed problem on 32-bit. |
46 |
int32_t new_val; |
47 |
uint32_t uval = (uint32_t) val; |
|
1
by brian
clean slate |
48 |
|
49 |
if (radix < 0) /* -10 */ |
|
50 |
{
|
|
51 |
if (val < 0) |
|
52 |
{
|
|
53 |
*dst++ = '-'; |
|
492.1.9
by Monty
Fixed problem on 32-bit. |
54 |
/* Avoid integer overflow in (-val) for INT32_MIN (BUG#31799). */
|
55 |
uval = (uint32_t)0 - uval; |
|
1
by brian
clean slate |
56 |
}
|
57 |
}
|
|
58 |
||
59 |
p = &buffer[sizeof(buffer)-1]; |
|
60 |
*p = '\0'; |
|
492.1.9
by Monty
Fixed problem on 32-bit. |
61 |
new_val= (int32_t) (uval / 10); |
62 |
*--p = '0'+ (char) (uval - (uint32_t) new_val * 10); |
|
1
by brian
clean slate |
63 |
val = new_val; |
64 |
||
65 |
while (val != 0) |
|
66 |
{
|
|
67 |
new_val=val/10; |
|
68 |
*--p = '0' + (char) (val-new_val*10); |
|
69 |
val= new_val; |
|
70 |
}
|
|
71 |
while ((*dst++ = *p++) != 0) ; |
|
72 |
return dst-1; |
|
73 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
74 |
|
75 |
} /* namespace internal */ |
|
76 |
} /* namespace drizzled */ |