Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
77ac40d7
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
77ac40d7
编写于
3月 02, 1998
作者:
T
Thomas G. Lockhart
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix money type USE_LOCALE support at least for default "C" locale.
Still has questionable code for some locale-specific strings.
上级
bb63cb8f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
53 addition
and
26 deletion
+53
-26
src/backend/utils/adt/cash.c
src/backend/utils/adt/cash.c
+53
-26
未找到文件。
src/backend/utils/adt/cash.c
浏览文件 @
77ac40d7
...
...
@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.2
2 1998/02/26 04:36:53 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.2
3 1998/03/02 00:13:36 thomas
Exp $
*/
#include <stdio.h>
...
...
@@ -34,7 +34,6 @@ static const char *num_word(Cash value);
#ifdef USE_LOCALE
static
struct
lconv
*
lconvert
=
NULL
;
#endif
/* cash_in()
...
...
@@ -46,6 +45,8 @@ static struct lconv *lconvert = NULL;
* XXX HACK It looks as though some of the symbols for
* monetary values returned by localeconv() can be multiple
* bytes/characters. This code assumes one byte only. - tgl 97/04/14
* XXX UNHACK Allow the currency symbol to be multi-byte.
* - thomas 1998-03-01
*/
Cash
*
cash_in
(
const
char
*
str
)
...
...
@@ -58,11 +59,11 @@ cash_in(const char *str)
int
seen_dot
=
0
;
const
char
*
s
=
str
;
int
fpoint
;
char
*
csymbol
;
char
dsymbol
,
ssymbol
,
psymbol
,
nsymbol
,
csymbol
;
*
nsymbol
;
#ifdef USE_LOCALE
#ifdef CASHDEBUG
...
...
@@ -76,33 +77,45 @@ cash_in(const char *str)
/* best guess is 2 in this case I think */
fpoint
=
((
lconvert
->
frac_digits
!=
CHAR_MAX
)
?
lconvert
->
frac_digits
:
2
);
/* int_frac_digits? */
dsymbol
=
*
lconvert
->
mon_decimal_point
;
ssymbol
=
*
lconvert
->
mon_thousands_sep
;
csymbol
=
*
lconvert
->
currency_symbol
;
psymbol
=
*
lconvert
->
positive_sign
;
nsymbol
=
*
lconvert
->
negative_sign
;
dsymbol
=
((
*
lconvert
->
mon_decimal_point
!=
'\0'
)
?
*
lconvert
->
mon_decimal_point
:
'.'
)
;
ssymbol
=
((
*
lconvert
->
mon_thousands_sep
!=
'\0'
)
?
*
lconvert
->
mon_thousands_sep
:
','
)
;
csymbol
=
((
*
lconvert
->
currency_symbol
!=
'\0'
)
?
lconvert
->
currency_symbol
:
"$"
)
;
psymbol
=
((
*
lconvert
->
positive_sign
!=
'\0'
)
?
*
lconvert
->
positive_sign
:
'+'
)
;
nsymbol
=
((
*
lconvert
->
negative_sign
!=
'\0'
)
?
lconvert
->
negative_sign
:
"-"
)
;
#else
fpoint
=
2
;
dsymbol
=
'.'
;
ssymbol
=
','
;
csymbol
=
'$'
;
csymbol
=
"$"
;
psymbol
=
'+'
;
nsymbol
=
'-'
;
nsymbol
=
"-"
;
#endif
#ifdef CASHDEBUG
printf
(
"cashin- precision %d; decimal %c; thousands %c; currency %c; positive %c; negative %c
\n
"
,
fpoint
,
dsymbol
,
ssymbol
,
csymbol
,
psymbol
,
nsymbol
);
printf
(
"cashin- precision '%d'; decimal '%c'; thousands '%c'; currency '%s'; positive '%c'; negative '%s'
\n
"
,
fpoint
,
dsymbol
,
ssymbol
,
csymbol
,
psymbol
,
nsymbol
);
#endif
/* we need to add all sorts of checking here. For now just */
/* strip all leading whitespace and any leading dollar sign */
while
(
isspace
(
*
s
)
||
*
s
==
csymbol
)
s
++
;
/* strip all leading whitespace and any leading currency symbol */
while
(
isspace
(
*
s
))
s
++
;
if
(
strncmp
(
s
,
csymbol
,
strlen
(
csymbol
))
==
0
)
s
+=
strlen
(
csymbol
);
#ifdef CASHDEBUG
printf
(
"cashin- string is '%s'
\n
"
,
s
);
#endif
/* a leading minus or paren signifies a negative number */
/* again, better heuristics needed */
if
(
*
s
==
nsymbol
||
*
s
==
'('
)
if
(
strncmp
(
s
,
nsymbol
,
strlen
(
nsymbol
))
==
0
)
{
sgn
=
-
1
;
s
+=
strlen
(
nsymbol
);
#ifdef CASHDEBUG
printf
(
"cashin- negative symbol; string is '%s'
\n
"
,
s
);
#endif
}
else
if
(
*
s
==
'('
)
{
sgn
=
-
1
;
s
++
;
...
...
@@ -113,8 +126,16 @@ cash_in(const char *str)
s
++
;
}
while
(
isspace
(
*
s
)
||
*
s
==
csymbol
)
s
++
;
#ifdef CASHDEBUG
printf
(
"cashin- string is '%s'
\n
"
,
s
);
#endif
while
(
isspace
(
*
s
))
s
++
;
if
(
strncmp
(
s
,
csymbol
,
strlen
(
csymbol
))
==
0
)
s
+=
strlen
(
csymbol
);
#ifdef CASHDEBUG
printf
(
"cashin- string is '%s'
\n
"
,
s
);
#endif
for
(;;
s
++
)
{
...
...
@@ -164,6 +185,10 @@ cash_in(const char *str)
*
result
=
(
value
*
sgn
);
#ifdef CASHDEBUG
printf
(
"cashin- result is %d
\n
"
,
*
result
);
#endif
return
(
result
);
}
/* cash_in() */
...
...
@@ -186,7 +211,7 @@ cash_out(Cash *in_value)
char
mon_group
,
comma
,
points
;
char
csymbol
,
char
*
csymbol
,
dsymbol
,
*
nsymbol
;
char
convention
;
...
...
@@ -196,18 +221,18 @@ cash_out(Cash *in_value)
lconvert
=
localeconv
();
mon_group
=
*
lconvert
->
mon_grouping
;
comma
=
*
lconvert
->
mon_thousands_sep
;
csymbol
=
*
lconvert
->
currency_symbol
;
dsymbol
=
*
lconvert
->
mon_decimal_point
;
nsymbol
=
lconvert
->
negative_sign
;
comma
=
((
*
lconvert
->
mon_thousands_sep
!=
'\0'
)
?
*
lconvert
->
mon_thousands_sep
:
','
);
/* frac_digits in the C locale seems to return CHAR_MAX */
/* best guess is 2 in this case I think */
points
=
((
lconvert
->
frac_digits
!=
CHAR_MAX
)
?
lconvert
->
frac_digits
:
2
);
/* int_frac_digits? */
convention
=
lconvert
->
n_sign_posn
;
dsymbol
=
((
*
lconvert
->
mon_decimal_point
!=
'\0'
)
?
*
lconvert
->
mon_decimal_point
:
'.'
);
csymbol
=
((
*
lconvert
->
currency_symbol
!=
'\0'
)
?
lconvert
->
currency_symbol
:
"$"
);
nsymbol
=
((
*
lconvert
->
negative_sign
!=
'\0'
)
?
lconvert
->
negative_sign
:
"-"
);
#else
mon_group
=
3
;
comma
=
','
;
csymbol
=
'$'
;
csymbol
=
"$"
;
dsymbol
=
'.'
;
nsymbol
=
"-"
;
points
=
2
;
...
...
@@ -217,6 +242,7 @@ cash_out(Cash *in_value)
point_pos
=
LAST_DIGIT
-
points
;
/* We're playing a little fast and loose with this. Shoot me. */
/* Not me, that was the other guy. Haven't fixed it yet - thomas */
if
(
!
mon_group
||
mon_group
==
CHAR_MAX
)
mon_group
=
3
;
...
...
@@ -249,7 +275,8 @@ cash_out(Cash *in_value)
value
/=
10
;
}
buf
[
count
]
=
csymbol
;
strncpy
((
buf
+
count
-
strlen
(
csymbol
)
+
1
),
csymbol
,
strlen
(
csymbol
));
count
-=
strlen
(
csymbol
)
-
1
;
if
(
buf
[
LAST_DIGIT
]
==
','
)
buf
[
LAST_DIGIT
]
=
buf
[
LAST_PAREN
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录