Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
d1fd7bda
Commit
d1fd7bda
authored
Nov 11, 2002
by
bar@bar.mysql.r18.ru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
thread charset related improvements
parent
9f019fea
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
8 deletions
+76
-8
sql/sql_string.cc
sql/sql_string.cc
+75
-8
sql/sql_string.h
sql/sql_string.h
+1
-0
No files found.
sql/sql_string.cc
View file @
d1fd7bda
...
...
@@ -93,18 +93,36 @@ bool String::realloc(uint32 alloc_length)
bool
String
::
set
(
longlong
num
,
CHARSET_INFO
*
cs
)
{
if
(
alloc
(
21
))
uint
l
=
20
*
cs
->
mbmaxlen
+
1
;
if
(
alloc
(
l
))
return
TRUE
;
if
(
cs
->
snprintf
==
my_snprintf_8bit
)
{
str_length
=
(
uint32
)
(
longlong10_to_str
(
num
,
Ptr
,
-
10
)
-
Ptr
);
}
else
{
str_length
=
cs
->
snprintf
(
cs
,
Ptr
,
l
,
"%d"
,
num
);
}
str_charset
=
cs
;
return
FALSE
;
}
bool
String
::
set
(
ulonglong
num
,
CHARSET_INFO
*
cs
)
{
if
(
alloc
(
21
))
uint
l
=
20
*
cs
->
mbmaxlen
+
1
;
if
(
alloc
(
l
))
return
TRUE
;
if
(
cs
->
snprintf
==
my_snprintf_8bit
)
{
str_length
=
(
uint32
)
(
longlong10_to_str
(
num
,
Ptr
,
10
)
-
Ptr
);
}
else
{
str_length
=
cs
->
snprintf
(
cs
,
Ptr
,
l
,
"%d"
,
num
);
}
str_charset
=
cs
;
return
FALSE
;
}
...
...
@@ -117,14 +135,14 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
if
(
decimals
>=
NOT_FIXED_DEC
)
{
sprintf
(
buff
,
"%.14g"
,
num
);
// Enough for a DATETIME
return
copy
(
buff
,
(
uint32
)
strlen
(
buff
),
my_charset_latin1
);
return
copy
(
buff
,
(
uint32
)
strlen
(
buff
),
my_charset_latin1
,
cs
);
}
#ifdef HAVE_FCONVERT
int
decpt
,
sign
;
char
*
pos
,
*
to
;
VOID
(
fconvert
(
num
,(
int
)
decimals
,
&
decpt
,
&
sign
,
buff
+
1
));
if
(
!
my_isdigit
(
system_charset_info
,
buff
[
1
]))
if
(
!
my_isdigit
(
my_charset_latin1
,
buff
[
1
]))
{
// Nan or Inf
pos
=
buff
+
1
;
if
(
sign
)
...
...
@@ -132,7 +150,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
buff
[
0
]
=
'-'
;
pos
=
buff
;
}
return
copy
(
pos
,(
uint32
)
strlen
(
pos
));
return
copy
(
pos
,(
uint32
)
strlen
(
pos
)
,
my_charset_latin1
,
cs
);
}
if
(
alloc
((
uint32
)
((
uint32
)
decpt
+
3
+
decimals
)))
return
TRUE
;
...
...
@@ -182,7 +200,7 @@ end:
#else
sprintf
(
buff
,
"%.*f"
,(
int
)
decimals
,
num
);
#endif
return
copy
(
buff
,(
uint32
)
strlen
(
buff
),
my_charset_latin1
);
return
copy
(
buff
,(
uint32
)
strlen
(
buff
),
my_charset_latin1
,
cs
);
#endif
}
...
...
@@ -219,6 +237,55 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
return
FALSE
;
}
/* Copy with charset convertion */
bool
String
::
copy
(
const
char
*
str
,
uint32
arg_length
,
CHARSET_INFO
*
from
,
CHARSET_INFO
*
to
)
{
uint32
new_length
=
to
->
mbmaxlen
*
arg_length
;
int
cnvres
;
my_wc_t
wc
;
const
uchar
*
s
=
(
const
uchar
*
)
str
;
const
uchar
*
se
=
s
+
arg_length
;
uchar
*
d
,
*
de
;
if
(
alloc
(
new_length
))
return
TRUE
;
d
=
(
uchar
*
)
Ptr
;
de
=
d
+
new_length
;
for
(
str_length
=
new_length
;
s
<
se
&&
d
<
de
;
)
{
if
((
cnvres
=
from
->
mb_wc
(
from
,
&
wc
,
s
,
se
))
>
0
)
{
s
+=
cnvres
;
}
else
if
(
cnvres
==
MY_CS_ILSEQ
)
{
s
++
;
wc
=
'?'
;
}
else
break
;
outp:
if
((
cnvres
=
to
->
wc_mb
(
to
,
wc
,
d
,
de
))
>
0
)
{
d
+=
cnvres
;
}
else
if
(
cnvres
==
MY_CS_ILUNI
&&
wc
!=
'?'
)
{
wc
=
'?'
;
goto
outp
;
}
else
break
;
}
Ptr
[
new_length
]
=
0
;
length
((
uint32
)
(
d
-
(
uchar
*
)
Ptr
));
str_charset
=
to
;
return
FALSE
;
}
/* This is used by mysql.cc */
bool
String
::
fill
(
uint32
max_length
,
char
fill_char
)
...
...
sql/sql_string.h
View file @
d1fd7bda
...
...
@@ -179,6 +179,7 @@ public:
bool
copy
();
// Alloc string if not alloced
bool
copy
(
const
String
&
s
);
// Allocate new string
bool
copy
(
const
char
*
s
,
uint32
arg_length
,
CHARSET_INFO
*
cs
);
// Allocate new string
bool
copy
(
const
char
*
s
,
uint32
arg_length
,
CHARSET_INFO
*
csfrom
,
CHARSET_INFO
*
csto
);
bool
append
(
const
String
&
s
);
bool
append
(
const
char
*
s
,
uint32
arg_length
=
0
);
bool
append
(
IO_CACHE
*
file
,
uint32
arg_length
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment