Skip to content
Open
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
24 changes: 24 additions & 0 deletions cstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,28 @@ double stringToDouble(TString s) {
return number + decimal;
}

int64_t stringToInt(TString s) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно добавить заголовок функции в начале файла

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И написать тесты в файл со всем тестами функций

int64_t result = 0;
int sign = 1;
size_t i = 0;

while (i < s.size && s.data[i] == ' ') {
i++;
}

if (i < s.size && s.data[i] == '-') {
sign = -1;
i++;
} else if (i < s.size && s.data[i] == '+') {
i++;
}

while (i < s.size && s.data[i] >= '0' && s.data[i] <= '9') {
result = result * 10 + (s.data[i] - '0');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно обработать переполнение int64_t

i++;
}

return result * sign;
}

#endif