Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
6d713f06
Commit
6d713f06
authored
Mar 24, 2011
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gear up for major use of ReadDelimitedText() by providing a better version
parent
62c9e7e0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
1 deletion
+57
-1
string.cpp
common/string.cpp
+44
-0
kicad_string.h
include/kicad_string.h
+11
-0
macros.h
include/macros.h
+2
-1
No files found.
common/string.cpp
View file @
6d713f06
...
...
@@ -8,6 +8,48 @@
#include "kicad_string.h"
int
ReadDelimitedText
(
wxString
*
aDest
,
const
char
*
aSource
)
{
std
::
string
utf8
;
// utf8 but without escapes and quotes.
bool
inside
=
false
;
const
char
*
start
=
aSource
;
char
cc
;
while
(
(
cc
=
*
aSource
++
)
!=
0
)
{
if
(
cc
==
'"'
)
{
if
(
inside
)
break
;
// 2nd double quote is end of delimited text
inside
=
true
;
// first delimiter found, make note, do not copy
}
else
if
(
inside
)
{
if
(
cc
==
'\\'
)
{
cc
=
*
aSource
++
;
if
(
!
cc
)
break
;
// do no copy the escape byte if it is followed by \ or "
if
(
cc
!=
'"'
&&
cc
!=
'\\'
)
utf8
+=
'\\'
;
utf8
+=
cc
;
}
else
utf8
+=
cc
;
}
}
*
aDest
=
FROM_UTF8
(
utf8
.
c_str
()
);
return
aSource
-
start
;
}
int
ReadDelimitedText
(
char
*
aDest
,
const
char
*
aSource
,
int
aDestSize
)
{
if
(
aDestSize
<=
0
)
...
...
@@ -33,6 +75,8 @@ int ReadDelimitedText( char* aDest, const char* aSource, int aDestSize )
if
(
cc
==
'\\'
)
{
cc
=
*
aSource
++
;
if
(
!
cc
)
break
;
// do no copy the escape byte if it is followed by \ or "
if
(
cc
!=
'"'
&&
cc
!=
'\\'
)
...
...
include/kicad_string.h
View file @
6d713f06
...
...
@@ -26,9 +26,20 @@ char* strlower( char* Text );
* @param aDestSize is the size of the destination byte buffer.
* @return int - the number of bytes read from source, which may be more than
* the number copied, due to escaping of double quotes and the escape byte itself.
* @deprecated should use the one which fetches a wxString, below.
*/
int
ReadDelimitedText
(
char
*
aDest
,
const
char
*
aSource
,
int
aDestSize
);
/**
* Function ReadDelimitedText
* copies bytes from @a aSource delimited string segment to @a aDest wxString.
*
* @param aDest is the destination wxString
* @param aSource is the source C string holding utf8 encoded bytes.
* @return int - the number of bytes read from source, which may be more than
* the number copied, due to escaping of double quotes and the escape byte itself.
*/
int
ReadDelimitedText
(
wxString
*
aDest
,
const
char
*
aSource
);
/**
* Function EscapedUTF8
...
...
include/macros.h
View file @
6d713f06
...
...
@@ -20,13 +20,14 @@
* converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
*/
//#define FROM_UTF8( cstring ) wxString::FromUTF8( cstring )
inline
wxString
FROM_UTF8
(
const
char
*
cstring
)
static
inline
wxString
FROM_UTF8
(
const
char
*
cstring
)
{
wxString
line
=
wxString
::
FromUTF8
(
cstring
);
if
(
line
.
IsEmpty
()
)
// happens when cstring is not a valid UTF8 sequence
line
=
wxConvCurrent
->
cMB2WC
(
cstring
);
// try to use locale conversion
return
line
;
}
/**
* Function GetChars
* returns a wxChar* to the actual character data within a wxString, and is
...
...
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