Commit 58c5282b authored by Victor Yacovlev's avatar Victor Yacovlev

Implemented lvalue string slices according to AGK/MR

parent ebcbb264
...@@ -1627,21 +1627,21 @@ public: ...@@ -1627,21 +1627,21 @@ public:
# if defined(WIN32) || defined(_WIN32) # if defined(WIN32) || defined(_WIN32)
const wchar_t * fmode; const wchar_t * fmode;
if (mode==FileType::Read) if (mode==FileType::Read)
fmode = L"r"; fmode = L"rb";
else if (mode==FileType::Write) else if (mode==FileType::Write)
fmode = L"w"; fmode = L"wb";
else if (mode==FileType::Append) else if (mode==FileType::Append)
fmode = L"a"; fmode = L"ab";
FILE * res = 0; FILE * res = 0;
_wfopen_s(&res, fileName.c_str(), fmode); _wfopen_s(&res, fileName.c_str(), fmode);
# else # else
const char * fmode; const char * fmode;
if (mode==FileType::Read) if (mode==FileType::Read)
fmode = "r"; fmode = "rb";
else if (mode==FileType::Write) else if (mode==FileType::Write)
fmode = "w"; fmode = "wb";
else if (mode==FileType::Append) else if (mode==FileType::Append)
fmode = "a"; fmode = "ab";
FILE* res = fopen(path, fmode); FILE* res = fopen(path, fmode);
# endif # endif
FileType f; FileType f;
......
...@@ -1776,7 +1776,20 @@ void KumirVM::do_specialcall(uint16_t alg) ...@@ -1776,7 +1776,20 @@ void KumirVM::do_specialcall(uint16_t alg)
String ch = first.value().toString(); String ch = first.value().toString();
s_error = Kumir::Core::getError(); s_error = Kumir::Core::getError();
if (s_error.length()==0) { if (s_error.length()==0) {
if (start==source.length()+1 && end<=start) { if (end<start && start==0) {
source = ch + source;
Variable r(source);
stack_values.push(r);
}
else if (start>source.length()) {
s_error = Kumir::Core::fromUtf8("Левая граница вырезки за пределами строки");
}
else if (end<start && start>0) {
source.insert(start, ch);
Variable r(source);
stack_values.push(r);
}
else if (start==source.length()+1 && end<=start) {
source.append(ch); source.append(ch);
Variable r(source); Variable r(source);
stack_values.push(r); stack_values.push(r);
...@@ -1788,9 +1801,7 @@ void KumirVM::do_specialcall(uint16_t alg) ...@@ -1788,9 +1801,7 @@ void KumirVM::do_specialcall(uint16_t alg)
s_error = Kumir::Core::fromUtf8("Левая граница вырезки за пределами строки"); s_error = Kumir::Core::fromUtf8("Левая граница вырезки за пределами строки");
} }
else if (end<start) { else if (end<start) {
source.insert(start-1, ch); s_error = Kumir::Core::fromUtf8("Ошибка в границах вырезки");
Variable r(source);
stack_values.push(r);
} }
else { else {
source = source.substr(0,start-1)+ch+source.substr(end); source = source.substr(0,start-1)+ch+source.substr(end);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment