FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
strw_convassign.c
Go to the documentation of this file.
1
/* ascii <-> unicode string convertion functions */
2
3
#include "
fb.h
"
4
5
FBCALL
FB_WCHAR
*
fb_WstrAssignFromA
6
(
7
FB_WCHAR
*dst,
8
ssize_t dst_chars,
9
void
*src,
10
ssize_t src_size
11
)
12
{
13
char
*src_ptr;
14
ssize_t src_chars;
15
16
if
( dst !=
NULL
)
17
{
18
FB_STRSETUP_FIX
( src, src_size, src_ptr, src_chars );
19
20
/* size unknown? assume it's big enough */
21
if
( dst_chars == 0 )
22
{
23
dst_chars = src_chars;
24
}
25
else
26
{
27
/* less the null-term */
28
--dst_chars;
29
}
30
31
fb_wstr_ConvFromA
( dst, dst_chars, src_ptr );
32
}
33
34
/* delete temp? */
35
if
( src_size == -1 )
36
fb_hStrDelTemp
( (
FBSTRING
*)src );
37
38
return
dst;
39
}
40
41
FBCALL
void
*
fb_WstrAssignToAEx
42
(
43
void
*dst,
44
ssize_t dst_chars,
45
FB_WCHAR
*src,
46
int
fill_rem,
47
int
is_init
48
)
49
{
50
ssize_t src_chars;
51
52
if
( dst ==
NULL
)
53
return
dst;
54
55
if
( src !=
NULL
)
56
src_chars =
fb_wstr_Len
( src );
57
else
58
src_chars = 0;
59
60
/* is dst var-len? */
61
if
( dst_chars == -1 )
62
{
63
/* src NULL? */
64
if
( src_chars == 0 )
65
{
66
if
( is_init ==
FB_FALSE
)
67
{
68
fb_StrDelete
( (
FBSTRING
*)dst );
69
}
70
else
71
{
72
((
FBSTRING
*)dst)->data =
NULL
;
73
((
FBSTRING
*)dst)->len = 0;
74
((
FBSTRING
*)dst)->size = 0;
75
}
76
}
77
else
78
{
79
/* realloc dst if needed and copy src */
80
if
( is_init ==
FB_FALSE
)
81
{
82
if
(
FB_STRSIZE
( dst ) != src_chars )
83
fb_hStrRealloc
( (
FBSTRING
*)dst, src_chars,
FB_FALSE
);
84
}
85
else
86
{
87
fb_hStrAlloc
( (
FBSTRING
*)dst, src_chars );
88
}
89
90
fb_wstr_ConvToA
( ((
FBSTRING
*)dst)->data, src, src_chars );
91
}
92
}
93
/* fixed-len or zstring.. */
94
else
95
{
96
/* src NULL? */
97
if
( src_chars == 0 )
98
{
99
*(
char
*)dst =
'\0'
;
100
}
101
else
102
{
103
/* byte ptr? as in C, assume dst is large enough */
104
if
( dst_chars == 0 )
105
dst_chars = src_chars;
106
107
fb_wstr_ConvToA
( (
char
*)dst,
108
src,
109
(dst_chars <= src_chars? dst_chars : src_chars) );
110
}
111
112
/* fill reminder with null's */
113
if
( fill_rem != 0 )
114
{
115
dst_chars -= src_chars;
116
if
( dst_chars > 0 )
117
memset( &(((
char
*)dst)[src_chars]), 0, dst_chars );
118
}
119
}
120
121
return
dst;
122
}
123
124
FBCALL
void
*
fb_WstrAssignToA
125
(
126
void
*dst,
127
ssize_t dst_chars,
128
FB_WCHAR
*src,
129
int
fill_rem
130
)
131
{
132
return
fb_WstrAssignToAEx
( dst, dst_chars, src, fill_rem,
FB_FALSE
);
133
}
134
135
FBCALL
void
*
fb_WstrAssignToA_Init
136
(
137
void
*dst,
138
ssize_t dst_chars,
139
FB_WCHAR
*src,
140
int
fill_rem
141
)
142
{
143
return
fb_WstrAssignToAEx
( dst, dst_chars, src, fill_rem,
FB_TRUE
);
144
}
rtlib
strw_convassign.c
Generated on Thu Jan 23 2014 19:40:13 for FreeBASIC by
1.8.4