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
dd15200c
Commit
dd15200c
authored
Sep 03, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Regex instead of wxRegEx everywhere
parent
9af99b57
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
36 deletions
+48
-36
src/data/locale.cpp
src/data/locale.cpp
+2
-2
src/data/symbol_font.cpp
src/data/symbol_font.cpp
+41
-33
src/render/text/element.cpp
src/render/text/element.cpp
+5
-1
No files found.
src/data/locale.cpp
View file @
dd15200c
...
...
@@ -12,9 +12,9 @@
#include <data/stylesheet.hpp>
#include <data/symbol_font.hpp>
#include <util/io/package_manager.hpp>
#include <util/regex.hpp>
#include <script/to_value.hpp>
#include <wx/wfstream.h>
#include <wx/regex.h>
#include <wx/stdpaths.h>
#if defined(__WXMSW__)
...
...
@@ -70,7 +70,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) {
// ----------------------------------------------------------------------------- : Wildcards
bool
match_wildcard
(
const
String
&
wildcard
,
const
String
&
name
)
{
return
wxRegEx
(
replace_all
(
replace_all
(
wildcard
,
_
(
"."
),
_
(
"
\\
."
)),
_
(
"*"
),
_
(
".*"
))).
M
atches
(
name
);
return
Regex
(
replace_all
(
replace_all
(
wildcard
,
_
(
"."
),
_
(
"
\\
."
)),
_
(
"*"
),
_
(
".*"
))).
m
atches
(
name
);
}
SubLocaleP
find_wildcard
(
map
<
String
,
SubLocaleP
>&
items
,
const
String
&
name
)
{
...
...
src/data/symbol_font.cpp
View file @
dd15200c
...
...
@@ -88,7 +88,7 @@ class SymbolInFont : public IntrusivePtrBase<SymbolInFont> {
Scriptable
<
bool
>
enabled
;
///< Is this symbol enabled?
bool
regex
;
///< Should this symbol be matched by a regex?
int
draw_text
;
///< The index of the captured regex expression to draw, or -1 to not draw text
wxRegEx
code_regex
;
///< Regex for matching the symbol code
Regex
code_regex
;
///< Regex for matching the symbol code
FontP
text_font
;
///< Font to draw text in.
Alignment
text_alignment
;
double
text_margin_left
;
...
...
@@ -109,7 +109,6 @@ SymbolInFont::SymbolInFont()
:
enabled
(
true
)
,
regex
(
false
)
,
draw_text
(
-
1
)
,
code_regex
()
,
text_alignment
(
ALIGN_MIDDLE_CENTER
)
,
text_margin_left
(
0
),
text_margin_right
(
0
)
,
text_margin_top
(
0
),
text_margin_bottom
(
0
)
...
...
@@ -177,7 +176,7 @@ IMPLEMENT_REFLECTION(SymbolInFont) {
REFLECT
(
regex
);
REFLECT_IF_READING
if
(
regex
)
code_regex
.
Compile
(
code
,
wxRE_ADVANCED
);
code_regex
.
assign
(
code
);
REFLECT
(
draw_text
);
REFLECT
(
text_font
);
REFLECT
(
text_alignment
);
...
...
@@ -198,28 +197,33 @@ void SymbolFont::split(const String& text, SplitSymbols& out) const {
// check symbol list
FOR_EACH_CONST
(
sym
,
symbols
)
{
if
(
!
sym
->
code
.
empty
()
&&
sym
->
enabled
)
{
size_t
start
,
len
=
1
;
if
(
sym
->
regex
&&
sym
->
code_regex
.
IsValid
()
&&
sym
->
code_regex
.
Matches
(
text
.
substr
(
pos
),
wxRE_NOTBOL
|
wxRE_NOTEOL
)
&&
sym
->
code_regex
.
GetMatch
(
&
start
,
&
len
)
&&
start
==
0
&&
len
>
0
)
{
//Matches the regex
if
(
sym
->
draw_text
>=
0
&&
sym
->
draw_text
<
(
int
)
sym
->
code_regex
.
GetMatchCount
())
{
size_t
draw_end
;
sym
->
code_regex
.
GetMatch
(
&
start
,
&
draw_end
,
sym
->
draw_text
);
out
.
push_back
(
DrawableSymbol
(
text
.
substr
(
pos
,
len
),
text
.
substr
(
pos
+
start
,
draw_end
-
start
),
*
sym
));
}
else
{
out
.
push_back
(
DrawableSymbol
(
text
.
substr
(
pos
,
len
),
_
(
""
),
*
sym
));
if
(
sym
->
regex
)
{
if
(
sym
->
code_regex
.
empty
())
{
sym
->
code_regex
.
assign
(
sym
->
code
);
}
Regex
::
Results
results
;
if
(
sym
->
code_regex
.
matches
(
results
,
text
.
begin
()
+
pos
,
text
.
end
())
&&
results
.
position
()
==
0
&&
results
.
length
()
>
0
)
{
//Matches the regex
if
(
sym
->
draw_text
>=
0
&&
sym
->
draw_text
<
(
int
)
results
.
size
())
{
out
.
push_back
(
DrawableSymbol
(
results
.
str
(),
results
.
str
(
sym
->
draw_text
),
*
sym
));
}
else
{
out
.
push_back
(
DrawableSymbol
(
results
.
str
(),
_
(
""
),
*
sym
));
}
pos
+=
results
.
length
();
goto
next_symbol
;
}
}
else
{
if
(
is_substr
(
text
,
pos
,
sym
->
code
))
{
out
.
push_back
(
DrawableSymbol
(
sym
->
code
,
sym
->
draw_text
>=
0
?
sym
->
code
:
_
(
""
),
*
sym
));
pos
+=
sym
->
code
.
size
();
goto
next_symbol
;
// continue two levels
}
pos
+=
len
;
goto
next_symbol
;
}
else
if
(
is_substr
(
text
,
pos
,
sym
->
code
))
{
out
.
push_back
(
DrawableSymbol
(
sym
->
code
,
sym
->
draw_text
>=
0
?
sym
->
code
:
_
(
""
),
*
sym
));
pos
+=
sym
->
code
.
size
();
goto
next_symbol
;
// continue two levels
}
}
}
...
...
@@ -236,14 +240,18 @@ size_t SymbolFont::recognizePrefix(const String& text, size_t start) const {
// check symbol list
FOR_EACH_CONST
(
sym
,
symbols
)
{
if
(
!
sym
->
code
.
empty
()
&&
sym
->
enabled
)
{
size_t
start
,
len
=
1
;
if
(
sym
->
regex
&&
sym
->
code_regex
.
IsValid
()
&&
sym
->
code_regex
.
Matches
(
text
.
substr
(
pos
),
wxRE_NOTBOL
|
wxRE_NOTEOL
)
&&
sym
->
code_regex
.
GetMatch
(
&
start
,
&
len
)
&&
start
==
0
&&
len
>
0
)
{
//Matches the regex
pos
+=
len
;
goto
next_symbol
;
}
else
if
(
is_substr
(
text
,
pos
,
sym
->
code
))
{
pos
+=
sym
->
code
.
size
();
goto
next_symbol
;
// continue two levels
if
(
sym
->
regex
)
{
Regex
::
Results
results
;
if
(
!
sym
->
code_regex
.
empty
()
&&
sym
->
code_regex
.
matches
(
results
,
text
.
begin
()
+
pos
,
text
.
end
())
&&
results
.
position
()
==
0
&&
results
.
length
()
>
0
)
{
//Matches the regex
pos
+=
results
.
length
();
goto
next_symbol
;
}
}
else
{
if
(
is_substr
(
text
,
pos
,
sym
->
code
))
{
pos
+=
sym
->
code
.
size
();
goto
next_symbol
;
// continue two levels
}
}
}
}
...
...
@@ -256,7 +264,7 @@ next_symbol:;
SymbolInFont
*
SymbolFont
::
defaultSymbol
()
const
{
FOR_EACH_CONST
(
sym
,
symbols
)
{
if
(
sym
->
regex
&&
sym
->
code_regex
.
Matches
(
_
(
"0"
))
&&
sym
->
enabled
)
return
sym
.
get
();
if
(
sym
->
enabled
&&
sym
->
regex
&&
sym
->
code_regex
.
matches
(
_
(
"0"
))
)
return
sym
.
get
();
}
return
nullptr
;
}
...
...
src/render/text/element.cpp
View file @
dd15200c
...
...
@@ -100,6 +100,7 @@ struct TextElementsFromString {
// text element before this tag?
addText
(
te
,
text
,
text_start
,
pos
,
style
,
ctx
);
}
// a (formatting) tag
size_t
tag_start
=
pos
;
pos
=
skip_tag
(
text
,
tag_start
);
if
(
is_substr
(
text
,
tag_start
,
_
(
"<b"
)))
bold
+=
1
;
...
...
@@ -177,18 +178,21 @@ struct TextElementsFromString {
}
else
{
// ignore other tags
}
// text starts again after the tag
text_start
=
pos
;
}
else
{
// normal text
pos
+=
1
;
}
}
if
(
text_start
<
end
)
{
// remaining text at the end
addText
(
te
,
text
,
text_start
,
end
,
style
,
ctx
);
}
}
private:
/// Create a text element for a piece of text
/// Create a text element for a piece of text
, text[start..end)
void
addText
(
TextElements
&
te
,
const
String
&
text
,
size_t
start
,
size_t
end
,
const
TextStyle
&
style
,
Context
&
ctx
)
{
String
content
=
untag
(
text
.
substr
(
start
,
end
-
start
));
assert
(
content
.
size
()
==
end
-
start
);
...
...
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