From 302c94627930e9965f7607497a01201fff3551e3 Mon Sep 17 00:00:00 2001 From: yinsimei Date: Thu, 6 Jul 2017 22:05:13 +0200 Subject: SLUDGE: use U32String to replace sludge utf8 library --- engines/sludge/builtin.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'engines/sludge/builtin.cpp') diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 1f19fc3b14..fc92161e3c 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -50,7 +50,7 @@ #include "sludge/thumbnail.h" #include "sludge/graphics.h" #include "sludge/sludge.h" -#include "sludge/CommonCode/utf8.h" +#include "sludge/utf8.h" namespace Sludge { @@ -558,9 +558,12 @@ builtIn(substring) { wholeString = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); - if (u8_strlen(wholeString) < start + length) { - length = u8_strlen(wholeString) - start; - if (u8_strlen(wholeString) < start) { + UTF8Converter convert(wholeString); + Common::U32String str32 = convert.getU32String(); + + if (str32.size() < start + length) { + length = str32.size() - start; + if (str32.size() < start) { start = 0; } } @@ -568,8 +571,8 @@ builtIn(substring) { length = 0; } - int startoffset = u8_offset(wholeString, start); - int endoffset = u8_offset(wholeString, start + length); + int startoffset = convert.getOriginOffset(start); + int endoffset = convert.getOriginOffset(start + length); newString = new char[endoffset - startoffset + 1]; if (!checkNew(newString)) { @@ -580,7 +583,7 @@ builtIn(substring) { newString[endoffset - startoffset] = 0; makeTextVar(fun->reg, newString); - delete newString; + delete []newString; return BR_CONTINUE; } -- cgit v1.2.3