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
2b15dcde
Commit
2b15dcde
authored
Jul 05, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed font size of code in keywords tab;
Added 'recursive' flag to replace_rule function
parent
8e3d3365
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
35 deletions
+48
-35
src/data/font.cpp
src/data/font.cpp
+5
-2
src/script/functions/basic.cpp
src/script/functions/basic.cpp
+43
-33
No files found.
src/data/font.cpp
View file @
2b15dcde
...
@@ -76,8 +76,11 @@ wxFont Font::toWxFont(double scale) const {
...
@@ -76,8 +76,11 @@ wxFont Font::toWxFont(double scale) const {
// make font
// make font
wxFont
font
;
wxFont
font
;
if
(
flags
&
FONT_CODE
)
{
if
(
flags
&
FONT_CODE
)
{
if
(
size_i
<
2
)
size_i
=
wxNORMAL_FONT
->
GetPointSize
();
if
(
size_i
<
2
)
{
font
=
wxFont
(
size_i
,
wxFONTFAMILY_TELETYPE
,
wxFONTSTYLE_NORMAL
,
weight_i
,
underline
(),
_
(
"Courier New"
));
return
wxFont
(
wxNORMAL_FONT
->
GetPointSize
(),
wxFONTFAMILY_TELETYPE
,
wxFONTSTYLE_NORMAL
,
weight_i
,
underline
(),
_
(
"Courier New"
));
}
else
{
font
=
wxFont
(
size_i
,
wxFONTFAMILY_TELETYPE
,
wxFONTSTYLE_NORMAL
,
weight_i
,
underline
(),
_
(
"Courier New"
));
}
}
else
if
(
name
().
empty
())
{
}
else
if
(
name
().
empty
())
{
font
=
*
wxNORMAL_FONT
;
font
=
*
wxNORMAL_FONT
;
font
.
SetPointSize
(
size
>
1
?
size_i
:
scale
*
font
.
GetPointSize
());
font
.
SetPointSize
(
size
>
1
?
size_i
:
scale
*
font
.
GetPointSize
());
...
...
src/script/functions/basic.cpp
View file @
2b15dcde
...
@@ -303,50 +303,58 @@ class ScriptReplaceRule : public ScriptValue {
...
@@ -303,50 +303,58 @@ class ScriptReplaceRule : public ScriptValue {
virtual
String
typeName
()
const
{
return
_
(
"replace_rule"
);
}
virtual
String
typeName
()
const
{
return
_
(
"replace_rule"
);
}
virtual
ScriptValueP
eval
(
Context
&
ctx
)
const
{
virtual
ScriptValueP
eval
(
Context
&
ctx
)
const
{
SCRIPT_PARAM
(
String
,
input
);
SCRIPT_PARAM
(
String
,
input
);
if
(
context
.
IsValid
()
||
replacement_function
)
{
if
(
context
.
IsValid
()
||
replacement_function
||
recursive
)
{
// match first, then check context of match
SCRIPT_RETURN
(
apply
(
ctx
,
input
));
String
ret
;
while
(
regex
.
Matches
(
input
))
{
// for each match ...
size_t
start
,
len
;
bool
ok
=
regex
.
GetMatch
(
&
start
,
&
len
,
0
);
assert
(
ok
);
ret
+=
input
.
substr
(
0
,
start
);
// everything before the match position stays
String
inside
=
input
.
substr
(
start
,
len
);
// inside the match
String
next_input
=
input
.
substr
(
start
+
len
);
// next loop the input is after this match
String
after_replace
=
ret
+
_
(
"<match>"
)
+
next_input
;
// after replacing, the resulting context would be
if
(
!
context
.
IsValid
()
||
context
.
Matches
(
after_replace
))
{
// the context matches -> perform replacement
if
(
replacement_function
)
{
// set match results in context
for
(
UInt
m
=
0
;
m
<
regex
.
GetMatchCount
()
;
++
m
)
{
regex
.
GetMatch
(
&
start
,
&
len
,
m
);
String
name
=
m
==
0
?
_
(
"input"
)
:
String
(
_
(
"_"
))
<<
m
;
String
value
=
input
.
substr
(
start
,
len
);
ctx
.
setVariable
(
name
,
to_script
(
value
));
}
// call
inside
=
replacement_function
->
eval
(
ctx
)
->
toString
();
}
else
{
regex
.
Replace
(
&
inside
,
replacement
,
1
);
// replace inside
}
}
ret
+=
inside
;
input
=
next_input
;
}
ret
+=
input
;
SCRIPT_RETURN
(
ret
);
}
else
{
}
else
{
// dumb replacing
// dumb replacing
regex
.
Replace
(
&
input
,
replacement
);
regex
.
Replace
(
&
input
,
replacement
);
SCRIPT_RETURN
(
input
);
SCRIPT_RETURN
(
input
);
}
}
}
}
String
apply
(
Context
&
ctx
,
String
&
input
,
int
level
=
0
)
const
{
// match first, then check context of match
String
ret
;
while
(
regex
.
Matches
(
input
))
{
// for each match ...
size_t
start
,
len
;
bool
ok
=
regex
.
GetMatch
(
&
start
,
&
len
,
0
);
assert
(
ok
);
ret
+=
input
.
substr
(
0
,
start
);
// everything before the match position stays
String
inside
=
input
.
substr
(
start
,
len
);
// inside the match
String
next_input
=
input
.
substr
(
start
+
len
);
// next loop the input is after this match
String
after_replace
=
ret
+
_
(
"<match>"
)
+
next_input
;
// after replacing, the resulting context would be
if
(
!
context
.
IsValid
()
||
context
.
Matches
(
after_replace
))
{
// the context matches -> perform replacement
if
(
replacement_function
)
{
// set match results in context
for
(
UInt
m
=
0
;
m
<
regex
.
GetMatchCount
()
;
++
m
)
{
regex
.
GetMatch
(
&
start
,
&
len
,
m
);
String
name
=
m
==
0
?
_
(
"input"
)
:
String
(
_
(
"_"
))
<<
m
;
String
value
=
input
.
substr
(
start
,
len
);
ctx
.
setVariable
(
name
,
to_script
(
value
));
}
// call
inside
=
replacement_function
->
eval
(
ctx
)
->
toString
();
}
else
{
regex
.
Replace
(
&
inside
,
replacement
,
1
);
// replace inside
}
}
if
(
recursive
&&
level
<
20
)
{
ret
+=
apply
(
ctx
,
inside
,
level
+
1
);
}
else
{
ret
+=
inside
;
}
input
=
next_input
;
}
ret
+=
input
;
return
ret
;
}
wxRegEx
regex
;
///< Regex to match
wxRegEx
regex
;
///< Regex to match
wxRegEx
context
;
///< Match only in a given context, optional
wxRegEx
context
;
///< Match only in a given context, optional
String
replacement
;
///< Replacement
String
replacement
;
///< Replacement
ScriptValueP
replacement_function
;
///< Replacement function instead of a simple string, optional
ScriptValueP
replacement_function
;
///< Replacement function instead of a simple string, optional
bool
recursive
;
///< Recurse into the replacement
};
};
// Create a regular expression rule for replacing in strings
// Create a regular expression rule for replacing in strings
...
@@ -370,6 +378,8 @@ ScriptValueP replace_rule(Context& ctx) {
...
@@ -370,6 +378,8 @@ ScriptValueP replace_rule(Context& ctx) {
throw
ScriptError
(
_
(
"Error while compiling regular expression: '"
)
+
in_context
+
_
(
"'"
));
throw
ScriptError
(
_
(
"Error while compiling regular expression: '"
)
+
in_context
+
_
(
"'"
));
}
}
}
}
SCRIPT_OPTIONAL_PARAM_
(
bool
,
recursive
);
ret
->
recursive
=
recursive
;
return
ret
;
return
ret
;
}
}
...
...
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