Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ $RECYCLE.BIN/

# Mac desktop service store files
.DS_Store
/.vs
26 changes: 26 additions & 0 deletions src/MoonSharp.Interpreter.Tests/EndToEnd/StringLibTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ public void String_GMatch_1()
Assert.AreEqual(DataType.String, res.Type);
Assert.AreEqual("HelloLuauser", res.String);
}
[Test]
public void String_GMatch_2()
{
string script = @"
s = 'Ррррр Нннннн Сссссс'
words = {}
for word in s:gmatch('%w+') do table.insert(words, word) end
return words
";

DynValue res = Script.RunString(script);
Assert.AreEqual(3, res.Table.Length);
Assert.AreEqual("Ррррр", res.Table.Get(1).String);
Assert.AreEqual("Нннннн", res.Table.Get(2).String);
Assert.AreEqual("Сссссс", res.Table.Get(3).String);

}

[Test]
public void String_Find_1()
Expand Down Expand Up @@ -238,6 +255,15 @@ public void String_GSub_3()
";
DynValue res = S.DoString(script);
}
[Test]
public void String_GSub_4()
{
string script = @"
return string.gsub('Ррррр Нннннн Сссссс','%S+', 'Z')
";
DynValue res = Script.RunString(script);
Assert.AreEqual("Z Z Z", res.Tuple[0].String);
}

[Test]
public void String_Match_1()
Expand Down
8 changes: 4 additions & 4 deletions src/MoonSharp.Interpreter/CoreLib/StringLib/KopiLua_StrLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static CharPtr max_expand(MatchState ms, CharPtr s,
CharPtr p, CharPtr ep)
{
ptrdiff_t i = 0; /* counts maximum expand for item */
while ((s + i < ms.src_end) && (singlematch((byte)(s[i]), p, ep) != 0))
while ((s + i < ms.src_end) && (singlematch(s[i], p, ep) != 0))
i++;
/* keeps trying to match with the maximum repetitions */
while (i >= 0)
Expand All @@ -273,7 +273,7 @@ private static CharPtr min_expand(MatchState ms, CharPtr s,
CharPtr res = match(ms, s, ep + 1);
if (res != null)
return res;
else if ((s < ms.src_end) && (singlematch((byte)(s[0]), p, ep) != 0))
else if ((s < ms.src_end) && (singlematch(s[0], p, ep) != 0))
s = s.next(); /* try with one more repetition */
else return null;
}
Expand Down Expand Up @@ -374,7 +374,7 @@ private static CharPtr match(MatchState ms, CharPtr s, CharPtr p)
//ismeretlen hiba miatt lett ide átmásolva
{ /* it is a pattern item */
CharPtr ep = classend(ms, p); /* points to what is next */
int m = (s < ms.src_end) && (singlematch((byte)(s[0]), p, ep) != 0) ? 1 : 0;
int m = (s < ms.src_end) && (singlematch(s[0], p, ep) != 0) ? 1 : 0;
switch (ep[0])
{
case '?':
Expand Down Expand Up @@ -421,7 +421,7 @@ private static CharPtr match(MatchState ms, CharPtr s, CharPtr p)
dflt:
{ /* it is a pattern item */
CharPtr ep = classend(ms, p); /* points to what is next */
int m = (s < ms.src_end) && (singlematch((byte)(s[0]), p, ep) != 0) ? 1 : 0;
int m = (s < ms.src_end) && (singlematch(s[0], p, ep) != 0) ? 1 : 0;
switch (ep[0])
{
case '?':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static CharPtr max_expand(MatchState ms, CharPtr s,
CharPtr p, CharPtr ep)
{
ptrdiff_t i = 0; /* counts maximum expand for item */
while ((s + i < ms.src_end) && (singlematch((byte)(s[i]), p, ep) != 0))
while ((s + i < ms.src_end) && (singlematch(s[i], p, ep) != 0))
i++;
/* keeps trying to match with the maximum repetitions */
while (i >= 0)
Expand All @@ -273,7 +273,7 @@ private static CharPtr min_expand(MatchState ms, CharPtr s,
CharPtr res = match(ms, s, ep + 1);
if (res != null)
return res;
else if ((s < ms.src_end) && (singlematch((byte)(s[0]), p, ep) != 0))
else if ((s < ms.src_end) && (singlematch(s[0], p, ep) != 0))
s = s.next(); /* try with one more repetition */
else return null;
}
Expand Down Expand Up @@ -374,7 +374,7 @@ private static CharPtr match(MatchState ms, CharPtr s, CharPtr p)
//ismeretlen hiba miatt lett ide átmásolva
{ /* it is a pattern item */
CharPtr ep = classend(ms, p); /* points to what is next */
int m = (s < ms.src_end) && (singlematch((byte)(s[0]), p, ep) != 0) ? 1 : 0;
int m = (s < ms.src_end) && (singlematch(s[0], p, ep) != 0) ? 1 : 0;
switch (ep[0])
{
case '?':
Expand Down Expand Up @@ -421,7 +421,7 @@ private static CharPtr match(MatchState ms, CharPtr s, CharPtr p)
dflt:
{ /* it is a pattern item */
CharPtr ep = classend(ms, p); /* points to what is next */
int m = (s < ms.src_end) && (singlematch((byte)(s[0]), p, ep) != 0) ? 1 : 0;
int m = (s < ms.src_end) && (singlematch(s[0], p, ep) != 0) ? 1 : 0;
switch (ep[0])
{
case '?':
Expand Down