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
558af6d7
Commit
558af6d7
authored
Feb 27, 2011
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add EscapedUTF8() and revise ReadDelimitedText() to complement it
parent
90dc2908
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
42 deletions
+104
-42
string.cpp
common/string.cpp
+59
-17
kicad_string.h
include/kicad_string.h
+25
-7
toolchain-mingw.cmake
new/toolchain-mingw.cmake
+1
-1
class_pcb_text.cpp
pcbnew/class_pcb_text.cpp
+17
-13
ioascii.cpp
pcbnew/ioascii.cpp
+2
-4
No files found.
common/string.cpp
View file @
558af6d7
...
...
@@ -8,32 +8,74 @@
#include "kicad_string.h"
/* read a double-quote delimited text from source and put it in in dest,
* read NbMaxChar bytes max
* return the char count read from source
*/
int
ReadDelimitedText
(
char
*
dest
,
char
*
source
,
int
NbMaxChar
)
int
ReadDelimitedText
(
char
*
aDest
,
const
char
*
aSource
,
int
aDestSize
)
{
if
(
aDestSize
<=
0
)
return
0
;
bool
inside
=
false
;
char
*
start
=
aDest
;
char
*
limit
=
aDest
+
aDestSize
-
1
;
char
cc
;
while
(
(
cc
=
*
aSource
++
)
!=
0
&&
aDest
<
limit
)
{
if
(
cc
==
'\\'
)
{
cc
=
*
aSource
++
;
if
(
inside
)
*
aDest
++
=
cc
;
}
else
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
)
{
*
aDest
++
=
cc
;
}
}
*
aDest
=
0
;
return
aDest
-
start
;
}
std
::
string
EscapedUTF8
(
const
wxString
&
aString
)
{
int
ii
,
jj
,
flag
=
0
;
std
::
string
utf8
=
TO_UTF8
(
aString
);
std
::
string
ret
;
for
(
ii
=
0
,
jj
=
0
;
ii
<
NbMaxChar
-
1
;
jj
++
,
source
++
)
// ret += '"';
for
(
std
::
string
::
const_iterator
it
=
utf8
.
begin
();
it
!=
utf8
.
end
();
++
it
)
{
if
(
*
source
==
0
)
break
;
/* E.O.L. */
if
(
*
source
==
'"'
)
/* delimiter is " */
// this escaping strategy is designed to be compatible with ReadDelimitedText():
if
(
*
it
==
'"'
)
{
if
(
flag
)
break
;
/* End of delimited text */
flag
=
1
;
/* First delimiter found. */
ret
+=
'\\'
;
ret
+=
'"'
;
}
else
if
(
flag
)
else
if
(
*
it
==
'\\'
)
{
*
dest
=
*
source
;
dest
++
;
ii
++
;
ret
+=
'\\'
;
// double it up
ret
+=
'\\'
;
}
else
ret
+=
*
it
;
}
*
dest
=
0
;
/* Null terminated */
return
jj
;
// ret += '"';
return
ret
;
}
...
...
include/kicad_string.h
View file @
558af6d7
...
...
@@ -14,14 +14,32 @@
char
*
strupper
(
char
*
Text
);
char
*
strlower
(
char
*
Text
);
/* Read string delimited with (") character.
* Upload NbMaxChar max
* Returns the number of codes read in source
* dest is terminated by NULL
/**
* Function ReadDelimitedText
* extracts bytes from @a aSource delimited string segment to @a aDest buffer.
* The extracted string will be null terminated even if truncation is necessary
* because aDestSize was not large enough.
*
* @param aDest is the destination byte buffer.
* @param aSource is the source bytes as a C string.
* @param aDestSize is the size of the destination byte buffer.
* @return int - the number of bytes extracted.
*/
int
ReadDelimitedText
(
char
*
dest
,
char
*
source
,
int
NbMaxChar
);
int
ReadDelimitedText
(
char
*
aDest
,
const
char
*
aSource
,
int
aDestSize
);
/**
* Function EscapedUTF8
* returns an 8 bit UTF8 string given aString in unicode form.
* Any double quoted or back slashes are prefixed with a '\\' byte and the form
* of this UTF8 byte string is compatible with function ReadDelimitedText().
*
* @param aString is the input string to convert.
* @return std::string - the escaped input text, without the wrapping double quotes.
*/
std
::
string
EscapedUTF8
(
const
wxString
&
aString
);
/* Read one line line from a file.
* Returns the first useful line read by eliminating blank lines and comments.
...
...
new/toolchain-mingw.cmake
View file @
558af6d7
...
...
@@ -7,7 +7,7 @@
# It is here to assist Dick with verifying compilation of /new stuff with mingw (under linux)
set
(
CMAKE_SYSTEM_NAME
Linux
)
set
(
CMAKE_SYSTEM_NAME
Windows
)
#-----<configuration>-----------------------------------------------
...
...
pcbnew/class_pcb_text.cpp
View file @
558af6d7
...
...
@@ -80,31 +80,31 @@ void TEXTE_PCB::Copy( TEXTE_PCB* source )
*/
int
TEXTE_PCB
::
ReadTextePcbDescr
(
LINE_READER
*
aReader
)
{
char
*
L
ine
;
char
*
l
ine
;
char
text
[
1024
];
char
style
[
256
];
while
(
aReader
->
ReadLine
()
)
{
L
ine
=
aReader
->
Line
();
if
(
strnicmp
(
L
ine
,
"$EndTEXTPCB"
,
11
)
==
0
)
l
ine
=
aReader
->
Line
();
if
(
strnicmp
(
l
ine
,
"$EndTEXTPCB"
,
11
)
==
0
)
return
0
;
if
(
strncmp
(
L
ine
,
"Te"
,
2
)
==
0
)
/* Text line (first line for multi line texts */
if
(
strncmp
(
l
ine
,
"Te"
,
2
)
==
0
)
/* Text line (first line for multi line texts */
{
ReadDelimitedText
(
text
,
L
ine
+
2
,
sizeof
(
text
)
);
ReadDelimitedText
(
text
,
l
ine
+
2
,
sizeof
(
text
)
);
m_Text
=
CONV_FROM_UTF8
(
text
);
continue
;
}
if
(
strncmp
(
L
ine
,
"nl"
,
2
)
==
0
)
/* next line of the current text */
if
(
strncmp
(
l
ine
,
"nl"
,
2
)
==
0
)
/* next line of the current text */
{
ReadDelimitedText
(
text
,
L
ine
+
2
,
sizeof
(
text
)
);
ReadDelimitedText
(
text
,
l
ine
+
2
,
sizeof
(
text
)
);
m_Text
.
Append
(
'\n'
);
m_Text
+=
CONV_FROM_UTF8
(
text
);
continue
;
}
if
(
strncmp
(
L
ine
,
"Po"
,
2
)
==
0
)
if
(
strncmp
(
l
ine
,
"Po"
,
2
)
==
0
)
{
sscanf
(
L
ine
+
2
,
" %d %d %d %d %d %d"
,
sscanf
(
l
ine
+
2
,
" %d %d %d %d %d %d"
,
&
m_Pos
.
x
,
&
m_Pos
.
y
,
&
m_Size
.
x
,
&
m_Size
.
y
,
&
m_Thickness
,
&
m_Orient
);
...
...
@@ -115,11 +115,11 @@ int TEXTE_PCB::ReadTextePcbDescr( LINE_READER* aReader )
m_Size
.
y
=
5
;
continue
;
}
if
(
strncmp
(
L
ine
,
"De"
,
2
)
==
0
)
if
(
strncmp
(
l
ine
,
"De"
,
2
)
==
0
)
{
style
[
0
]
=
0
;
int
normal_display
=
1
;
sscanf
(
L
ine
+
2
,
" %d %d %lX %s
\n
"
,
&
m_Layer
,
&
normal_display
,
sscanf
(
l
ine
+
2
,
" %d %d %lX %s
\n
"
,
&
m_Layer
,
&
normal_display
,
&
m_TimeStamp
,
style
);
m_Mirror
=
normal_display
?
false
:
true
;
...
...
@@ -157,18 +157,22 @@ bool TEXTE_PCB::Save( FILE* aFile ) const
const
char
*
style
=
m_Italic
?
"Italic"
:
"Normal"
;
wxArrayString
*
list
=
wxStringSplit
(
m_Text
,
'\n'
);
for
(
unsigned
ii
=
0
;
ii
<
list
->
Count
();
ii
++
)
{
wxString
txt
=
list
->
Item
(
ii
);
if
(
ii
==
0
)
fprintf
(
aFile
,
"Te
\"
%s
\"\n
"
,
CONV_TO_UTF8
(
txt
)
);
fprintf
(
aFile
,
"Te
\"
%s
\"\n
"
,
EscapedUTF8
(
txt
).
c_str
(
)
);
else
fprintf
(
aFile
,
"nl
\"
%s
\"\n
"
,
CONV_TO_UTF8
(
txt
)
);
}
delete
(
list
);
delete
list
;
fprintf
(
aFile
,
"Po %d %d %d %d %d %d
\n
"
,
m_Pos
.
x
,
m_Pos
.
y
,
m_Size
.
x
,
m_Size
.
y
,
m_Thickness
,
m_Orient
);
fprintf
(
aFile
,
"De %d %d %lX %s
\n
"
,
m_Layer
,
m_Mirror
?
0
:
1
,
m_TimeStamp
,
style
);
...
...
pcbnew/ioascii.cpp
View file @
558af6d7
...
...
@@ -327,13 +327,11 @@ int WinEDA_BasePcbFrame::ReadSetup( LINE_READER* aReader )
}
catch
(
IO_ERROR
&
e
)
{
#if 1
wxString
msg
;
msg
.
Printf
(
wxT
(
"Error reading PcbPlotParams from %s:
\n
%s"
),
msg
.
Printf
(
_
(
"Error reading PcbPlotParams from %s:
\n
%s"
),
aReader
->
GetSource
().
GetData
(),
e
.
errorText
.
GetData
()
);
wxMessageBox
(
msg
,
wxT
(
"Open Board File"
),
wxICON_ERROR
);
#endif
wxMessageBox
(
msg
,
_
(
"Open Board File"
),
wxICON_ERROR
);
}
continue
;
...
...
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