mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Fix handling braces in tokens
This brings Tokenizer changes from changeset
423fec90b3
This commit is contained in:
parent
db1efab940
commit
715d557f32
@ -59,7 +59,7 @@ namespace Orchard.Tokens.Implementation {
|
||||
private static Tuple<string, IEnumerable<string>> Parse(string text, bool hashMode) {
|
||||
var tokens = new List<string>();
|
||||
if (!String.IsNullOrEmpty(text)) {
|
||||
var inToken = false;
|
||||
var inTokenDepth = 0;
|
||||
var tokenStart = 0;
|
||||
for (var i = 0; i < text.Length; i++) {
|
||||
var c = text[i];
|
||||
@ -70,29 +70,32 @@ namespace Orchard.Tokens.Implementation {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (c == '}' && !(inToken)) {
|
||||
else if (c == '}' && inTokenDepth == 0) {
|
||||
if (i + 1 < text.Length && text[i + 1] == '}') {
|
||||
text = text.Substring(0, i) + text.Substring(i + 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (inToken) {
|
||||
if (inTokenDepth > 0) {
|
||||
if (c == '}') {
|
||||
inToken = false;
|
||||
var token = text.Substring(tokenStart + 1, i - tokenStart - 1);
|
||||
tokens.Add(token);
|
||||
inTokenDepth--;
|
||||
if (inTokenDepth == 0) {
|
||||
var token = text.Substring(tokenStart + 1, i - tokenStart - 1);
|
||||
tokens.Add(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!hashMode && c == '{') {
|
||||
inToken = true;
|
||||
tokenStart = i;
|
||||
|
||||
if (!hashMode && c == '{') {
|
||||
if (inTokenDepth == 0) tokenStart = i;
|
||||
inTokenDepth++;
|
||||
}
|
||||
else if (hashMode && c == '#'
|
||||
&& i + 1 < text.Length && text[i + 1] == '{'
|
||||
&& (i + 2 > text.Length || text[i + 2] != '{') ) {
|
||||
inToken = true;
|
||||
tokenStart = i+1;
|
||||
&& (i + 2 > text.Length || text[i + 2] != '{') ) {
|
||||
if (inTokenDepth == 0) tokenStart = i+1;
|
||||
inTokenDepth++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user