2013-11-23 21:34:54 +01:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 02:34:18 +01:00
|
|
|
*
|
2013-11-23 21:34:54 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/ustr.h"
|
2020-06-22 23:29:25 +05:30
|
|
|
#include "common/str.h"
|
2013-11-23 21:34:54 +01:00
|
|
|
#include "common/memorypool.h"
|
|
|
|
#include "common/util.h"
|
2020-05-11 19:18:37 +03:00
|
|
|
#include "unicode-bidi.h"
|
2013-11-23 21:34:54 +01:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
2020-10-31 16:56:00 +00:00
|
|
|
U32String::U32String(const char *str) : BaseString<u32char_type_t>() {
|
2019-01-01 00:40:17 -08:00
|
|
|
if (str == nullptr) {
|
|
|
|
_storage[0] = 0;
|
|
|
|
_size = 0;
|
|
|
|
} else {
|
|
|
|
initWithCStr(str, strlen(str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 16:56:00 +00:00
|
|
|
U32String::U32String(const char *str, uint32 len) : BaseString<u32char_type_t>() {
|
2019-01-01 00:40:17 -08:00
|
|
|
initWithCStr(str, len);
|
|
|
|
}
|
|
|
|
|
2020-10-31 16:56:00 +00:00
|
|
|
U32String::U32String(const char *beginP, const char *endP) : BaseString<u32char_type_t>() {
|
2019-01-01 00:40:17 -08:00
|
|
|
assert(endP >= beginP);
|
|
|
|
initWithCStr(beginP, endP - beginP);
|
|
|
|
}
|
|
|
|
|
2020-10-31 16:56:00 +00:00
|
|
|
U32String::U32String(const String &str) : BaseString<u32char_type_t>() {
|
2019-01-01 00:40:17 -08:00
|
|
|
initWithCStr(str.c_str(), str.size());
|
|
|
|
}
|
|
|
|
|
2020-10-31 16:56:00 +00:00
|
|
|
U32String::U32String(const UnicodeBiDiText &txt) : BaseString<u32char_type_t>() {
|
2020-10-27 23:22:25 +01:00
|
|
|
initWithValueTypeStr(txt.visual.c_str(), txt.visual.size());
|
2020-05-11 19:18:37 +03:00
|
|
|
}
|
|
|
|
|
2013-11-23 21:34:54 +01:00
|
|
|
U32String::~U32String() {
|
|
|
|
decRefCount(_extern._refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
U32String &U32String::operator=(const U32String &str) {
|
2020-10-27 23:22:25 +01:00
|
|
|
assign(str);
|
2013-11-23 21:34:54 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-01-01 00:40:17 -08:00
|
|
|
U32String &U32String::operator=(const String &str) {
|
2020-08-31 23:59:47 +01:00
|
|
|
clear();
|
2019-01-01 00:40:17 -08:00
|
|
|
initWithCStr(str.c_str(), str.size());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
U32String &U32String::operator=(const value_type *str) {
|
|
|
|
return U32String::operator=(U32String(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
U32String &U32String::operator=(const char *str) {
|
2020-08-31 23:59:47 +01:00
|
|
|
clear();
|
2019-01-01 00:40:17 -08:00
|
|
|
initWithCStr(str, strlen(str));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-23 21:34:54 +01:00
|
|
|
U32String &U32String::operator+=(const U32String &str) {
|
|
|
|
if (&str == this) {
|
|
|
|
return operator+=(U32String(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
int len = str._size;
|
|
|
|
if (len > 0) {
|
|
|
|
ensureCapacity(_size + len, true);
|
|
|
|
|
|
|
|
memcpy(_str + _size, str._str, (len + 1) * sizeof(value_type));
|
|
|
|
_size += len;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
U32String &U32String::operator+=(value_type c) {
|
|
|
|
ensureCapacity(_size + 1, true);
|
|
|
|
|
|
|
|
_str[_size++] = c;
|
|
|
|
_str[_size] = 0;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-01-01 00:40:17 -08:00
|
|
|
bool U32String::operator==(const String &x) const {
|
2020-10-27 23:22:25 +01:00
|
|
|
return equalsC(x.c_str());
|
2019-01-01 00:40:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool U32String::operator==(const char *x) const {
|
2020-10-27 23:22:25 +01:00
|
|
|
return equalsC(x);
|
2019-01-01 00:40:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool U32String::operator!=(const String &x) const {
|
2020-10-27 23:22:25 +01:00
|
|
|
return !equalsC(x.c_str());
|
2019-01-01 00:40:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool U32String::operator!=(const char *x) const {
|
2020-10-27 23:22:25 +01:00
|
|
|
return !equalsC(x);
|
2019-12-26 15:24:07 +01:00
|
|
|
}
|
|
|
|
|
2019-10-18 17:18:54 +02:00
|
|
|
U32String operator+(const U32String &x, const U32String &y) {
|
|
|
|
U32String temp(x);
|
|
|
|
temp += y;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2020-10-31 23:52:11 +01:00
|
|
|
U32String operator+(const U32String &x, const U32String::value_type y) {
|
2020-10-27 23:22:25 +01:00
|
|
|
U32String temp(x);
|
|
|
|
temp += y;
|
|
|
|
return temp;
|
2020-07-21 04:24:04 +05:30
|
|
|
}
|
|
|
|
|
2020-10-27 23:22:25 +01:00
|
|
|
void U32String::insertString(const char *s, uint32 p) {
|
|
|
|
while (*s != '\0') {
|
2020-10-31 21:32:36 +00:00
|
|
|
BaseString<u32char_type_t>::insertChar(*s++, p++);
|
2020-06-11 21:24:05 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 23:22:25 +01:00
|
|
|
void U32String::insertString(const String &s, uint32 p) {
|
|
|
|
for (uint32 i = 0; i < s.size(); ++i) {
|
2020-10-31 21:32:36 +00:00
|
|
|
BaseString<u32char_type_t>::insertChar(s[i], p++);
|
2020-06-13 22:12:25 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 20:29:52 +05:30
|
|
|
U32String U32String::format(U32String fmt, ...) {
|
2020-06-24 18:44:08 +05:30
|
|
|
U32String output;
|
2020-06-13 22:12:25 +05:30
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2020-10-27 23:22:25 +01:00
|
|
|
U32String::vformat(fmt.c_str(), fmt.c_str() + fmt.size(), output, va);
|
2020-06-13 22:12:25 +05:30
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2020-09-08 21:22:04 +01:00
|
|
|
U32String U32String::format(const char *fmt, ...) {
|
|
|
|
U32String output;
|
|
|
|
|
|
|
|
Common::U32String fmtU32(fmt);
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2020-10-27 23:22:25 +01:00
|
|
|
U32String::vformat(fmtU32.c_str(), fmtU32.c_str() + fmtU32.size(),
|
|
|
|
output, va);
|
2020-09-08 21:22:04 +01:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2020-10-27 23:22:25 +01:00
|
|
|
int U32String::vformat(const value_type *fmt, const value_type *fmtEnd, U32String &output, va_list args) {
|
2020-06-18 20:29:52 +05:30
|
|
|
int int_temp;
|
|
|
|
char *string_temp;
|
|
|
|
|
2020-08-19 17:03:50 +05:30
|
|
|
value_type ch;
|
2020-08-20 00:03:54 +05:30
|
|
|
value_type *u32string_temp;
|
2020-06-18 20:29:52 +05:30
|
|
|
int length = 0;
|
|
|
|
int len = 0;
|
|
|
|
int pos = 0;
|
2020-08-20 00:03:54 +05:30
|
|
|
int tempPos = 0;
|
2020-06-18 20:29:52 +05:30
|
|
|
|
|
|
|
char buffer[512];
|
|
|
|
|
2020-10-27 23:22:25 +01:00
|
|
|
while (fmt != fmtEnd) {
|
2020-06-18 20:29:52 +05:30
|
|
|
ch = *fmt++;
|
|
|
|
if (ch == '%') {
|
2020-06-24 17:40:09 +05:30
|
|
|
switch (ch = *fmt++) {
|
2020-08-20 00:03:54 +05:30
|
|
|
case 'S':
|
2020-08-30 22:50:13 +05:30
|
|
|
u32string_temp = va_arg(args, value_type *);
|
2020-08-20 00:03:54 +05:30
|
|
|
|
|
|
|
tempPos = output.size();
|
|
|
|
output.insertString(u32string_temp, pos);
|
|
|
|
len = output.size() - tempPos;
|
|
|
|
length += len;
|
|
|
|
|
|
|
|
pos += len - 1;
|
|
|
|
break;
|
2020-06-18 20:29:52 +05:30
|
|
|
case 's':
|
|
|
|
string_temp = va_arg(args, char *);
|
2020-10-27 23:22:25 +01:00
|
|
|
tempPos = output.size();
|
2020-06-18 20:29:52 +05:30
|
|
|
output.insertString(string_temp, pos);
|
2020-10-27 23:22:25 +01:00
|
|
|
len = output.size() - tempPos;
|
|
|
|
length += len;
|
2020-06-22 22:05:11 +05:30
|
|
|
pos += len - 1;
|
2020-06-18 20:29:52 +05:30
|
|
|
break;
|
2020-08-31 00:19:53 +05:30
|
|
|
case 'i':
|
|
|
|
// fallthrough intended
|
2020-06-18 20:29:52 +05:30
|
|
|
case 'd':
|
|
|
|
int_temp = va_arg(args, int);
|
|
|
|
itoa(int_temp, buffer, 10);
|
|
|
|
len = strlen(buffer);
|
|
|
|
length += len;
|
2020-06-22 22:05:11 +05:30
|
|
|
|
|
|
|
output.insertString(buffer, pos);
|
|
|
|
pos += len - 1;
|
2020-06-18 20:29:52 +05:30
|
|
|
break;
|
2020-06-30 03:40:13 +05:30
|
|
|
case 'u':
|
|
|
|
int_temp = va_arg(args, uint);
|
|
|
|
itoa(int_temp, buffer, 10);
|
|
|
|
len = strlen(buffer);
|
|
|
|
length += len;
|
|
|
|
|
|
|
|
output.insertString(buffer, pos);
|
|
|
|
pos += len - 1;
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 18:06:37 +05:30
|
|
|
break;
|
2020-09-12 11:53:03 +01:00
|
|
|
case 'c':
|
|
|
|
//char is promoted to int when passed through '...'
|
|
|
|
int_temp = va_arg(args, int);
|
|
|
|
output.insertChar(int_temp, pos);
|
|
|
|
++length;
|
|
|
|
break;
|
2020-06-18 20:29:52 +05:30
|
|
|
default:
|
2020-06-24 18:44:08 +05:30
|
|
|
warning("Unexpected formatting type for U32String::Format.");
|
2020-06-18 20:29:52 +05:30
|
|
|
break;
|
|
|
|
}
|
2020-06-24 18:44:08 +05:30
|
|
|
} else {
|
|
|
|
output += *(fmt - 1);
|
2020-06-18 20:29:52 +05:30
|
|
|
}
|
|
|
|
pos++;
|
2020-06-13 22:12:25 +05:30
|
|
|
}
|
2020-06-18 20:29:52 +05:30
|
|
|
return length;
|
2020-06-13 22:12:25 +05:30
|
|
|
}
|
|
|
|
|
2020-06-24 17:40:09 +05:30
|
|
|
char* U32String::itoa(int num, char* str, int base) {
|
|
|
|
int i = 0;
|
|
|
|
|
2020-09-06 13:20:05 +01:00
|
|
|
if (num) {
|
|
|
|
// go digit by digit
|
|
|
|
while (num != 0) {
|
|
|
|
int rem = num % base;
|
|
|
|
str[i++] = rem + '0';
|
|
|
|
num /= base;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
str[i++] = '0';
|
2020-06-24 17:40:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// append string terminator
|
|
|
|
str[i] = '\0';
|
|
|
|
int k = 0;
|
|
|
|
int j = i - 1;
|
|
|
|
|
|
|
|
// reverse the string
|
|
|
|
while (k < j) {
|
|
|
|
char temp = str[k];
|
|
|
|
str[k] = str[j];
|
|
|
|
str[j] = temp;
|
|
|
|
k++;
|
|
|
|
j--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-11-23 21:34:54 +01:00
|
|
|
} // End of namespace Common
|