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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
16 |
#include <config.h> |
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]; |
|
492.1.9
by Monty
Fixed problem on 32-bit. |
45 |
int32_t new_val; |
46 |
uint32_t uval = (uint32_t) val; |
|
1
by brian
clean slate |
47 |
|
48 |
if (radix < 0) /* -10 */ |
|
49 |
{
|
|
50 |
if (val < 0) |
|
51 |
{
|
|
52 |
*dst++ = '-'; |
|
492.1.9
by Monty
Fixed problem on 32-bit. |
53 |
/* Avoid integer overflow in (-val) for INT32_MIN (BUG#31799). */
|
54 |
uval = (uint32_t)0 - uval; |
|
1
by brian
clean slate |
55 |
}
|
56 |
}
|
|
57 |
||
2194.3.1
by Olaf van der Spek
Remove register keyword |
58 |
char* p = &buffer[sizeof(buffer)-1]; |
1
by brian
clean slate |
59 |
*p = '\0'; |
492.1.9
by Monty
Fixed problem on 32-bit. |
60 |
new_val= (int32_t) (uval / 10); |
61 |
*--p = '0'+ (char) (uval - (uint32_t) new_val * 10); |
|
1
by brian
clean slate |
62 |
val = new_val; |
63 |
||
64 |
while (val != 0) |
|
65 |
{
|
|
66 |
new_val=val/10; |
|
67 |
*--p = '0' + (char) (val-new_val*10); |
|
68 |
val= new_val; |
|
69 |
}
|
|
70 |
while ((*dst++ = *p++) != 0) ; |
|
71 |
return dst-1; |
|
72 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
73 |
|
74 |
} /* namespace internal */ |
|
75 |
} /* namespace drizzled */ |