Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
7104e9a7
Commit
7104e9a7
authored
Apr 05, 2011
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
to_code for strings now adds quotes and escapes
parent
4058bc80
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
src/script/to_value.hpp
src/script/to_value.hpp
+1
-0
src/script/value.cpp
src/script/value.cpp
+19
-5
No files found.
src/script/to_value.hpp
View file @
7104e9a7
...
...
@@ -400,6 +400,7 @@ inline ScriptValueP to_script(long v) { return to_script((int) v); }
ScriptValueP
to_script
(
AColor
v
);
ScriptValueP
to_script
(
wxDateTime
v
);
inline
ScriptValueP
to_script
(
bool
v
)
{
return
v
?
script_true
:
script_false
;
}
inline
ScriptValueP
to_script
(
ScriptValueP
const
&
v
)
{
return
v
;
}
template
<
typename
T
>
inline
ScriptValueP
to_script
(
const
vector
<
T
>*
v
)
{
return
intrusive
(
new
ScriptCollection
<
vector
<
T
>
>
(
v
));
}
template
<
typename
K
,
typename
V
>
...
...
src/script/value.cpp
View file @
7104e9a7
...
...
@@ -224,6 +224,22 @@ ScriptValueP to_script(double v) {
// ----------------------------------------------------------------------------- : String type
String
quote_string
(
String
const
&
str
)
{
String
out
;
out
.
reserve
(
str
.
size
()
+
2
);
out
+=
_
(
'"'
);
FOR_EACH_CONST
(
c
,
str
)
{
if
(
c
==
_
(
'"'
)
||
c
==
_
(
'\\'
))
{
out
+=
_
(
'\\'
);
out
+=
c
;
}
else
if
(
c
==
_
(
'\1'
))
out
+=
_
(
"
\\
<"
);
else
if
(
c
==
_
(
'\n'
))
out
+=
_
(
"
\\
n"
);
else
if
(
c
==
_
(
'\r'
))
out
+=
_
(
"
\\
r"
);
else
if
(
c
==
_
(
'\t'
))
out
+=
_
(
"
\\
t"
);
else
out
+=
c
;
}
out
+=
_
(
'"'
);
return
out
;
}
// String values
class
ScriptString
:
public
ScriptValue
{
public:
...
...
@@ -231,6 +247,9 @@ class ScriptString : public ScriptValue {
virtual
ScriptType
type
()
const
{
return
SCRIPT_STRING
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"string"
)
+
_
(
" (
\"
"
)
+
(
value
.
size
()
<
30
?
value
:
value
.
substr
(
0
,
30
)
+
_
(
"..."
))
+
_
(
"
\"
)"
);
}
virtual
String
toString
()
const
{
return
value
;
}
virtual
String
toCode
()
const
{
return
quote_string
(
value
);
}
virtual
double
toDouble
()
const
{
double
d
;
if
(
value
.
ToDouble
(
&
d
))
{
...
...
@@ -358,11 +377,6 @@ class ScriptNil : public ScriptValue {
virtual
GeneratedImageP
toImage
()
const
{
return
intrusive
(
new
BlankImage
());
}
virtual
CompareWhat
compareAs
(
String
&
compare_str
,
void
const
*&
)
const
{
// TODO: do we want both nil=="" and nil==0? Then we would get non-transitive equality
compare_str
.
clear
();
return
COMPARE_AS_STRING
;
}
protected:
virtual
ScriptValueP
do_eval
(
Context
&
ctx
,
bool
)
const
{
...
...
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