Changed Append() methods implementation in String class so they can be chained together in a statement. Added new Join() methods and exposed it to Script API. Refactored Attribute Inspector to take advantage of the new exposed Join() method.
This commit is contained in:
parent
9ed0c43919
commit
990428ca4d
@ -451,7 +451,10 @@ void LoadAttributeEditor(UIElement@ parent, Variant value, VariantType type, Arr
|
||||
for (uint j = 1; j < coordinates.length; ++j)
|
||||
{
|
||||
if (coordinates[j][i] != value)
|
||||
{
|
||||
sameValue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SetEditable(SetValue(parent.children[i + 1], value, sameValue), editable && sameValue);
|
||||
}
|
||||
@ -525,42 +528,6 @@ void GetEditorValue(UIElement@ parent, VariantType type, Array<String>@ enumName
|
||||
}
|
||||
else if (type == VAR_FLOAT)
|
||||
FillValue(values, Variant(attrEdit.text.ToFloat()));
|
||||
else if (type == VAR_VECTOR2)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
{
|
||||
float[] data = values[i].GetVector2().data;
|
||||
data[coordinate] = attrEdit.text.ToFloat();
|
||||
values[i] = Vector2(data);
|
||||
}
|
||||
}
|
||||
else if (type == VAR_VECTOR3)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
{
|
||||
float[] data = values[i].GetVector3().data;
|
||||
data[coordinate] = attrEdit.text.ToFloat();
|
||||
values[i] = Vector3(data);
|
||||
}
|
||||
}
|
||||
else if (type == VAR_VECTOR4)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
{
|
||||
float[] data = values[i].GetVector4().data;
|
||||
data[coordinate] = attrEdit.text.ToFloat();
|
||||
values[i] = Vector4(data);
|
||||
}
|
||||
}
|
||||
else if (type == VAR_COLOR)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
{
|
||||
float[] data = values[i].GetColor().data;
|
||||
data[coordinate] = attrEdit.text.ToFloat();
|
||||
values[i] = Color(data);
|
||||
}
|
||||
}
|
||||
else if (type == VAR_QUATERNION)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
@ -570,6 +537,15 @@ void GetEditorValue(UIElement@ parent, VariantType type, Array<String>@ enumName
|
||||
values[i] = Quaternion(Vector3(data));
|
||||
}
|
||||
}
|
||||
else if (type >= VAR_VECTOR2 && type <= VAR_COLOR)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
{
|
||||
String[] data = values[i].ToString().Split(' ');
|
||||
data[coordinate] = String(attrEdit.text.ToFloat());
|
||||
values[i] = Variant(type, Join(data, " "));
|
||||
}
|
||||
}
|
||||
else if (type == VAR_INT)
|
||||
{
|
||||
if (enumNames is null || enumNames.empty)
|
||||
@ -588,22 +564,13 @@ void GetEditorValue(UIElement@ parent, VariantType type, Array<String>@ enumName
|
||||
ref.type = ShortStringHash(attrEdit.vars["Type"].GetUInt());
|
||||
FillValue(values, Variant(ref));
|
||||
}
|
||||
else if (type == VAR_INTVECTOR2)
|
||||
else if (type == VAR_INTVECTOR2 || type == VAR_INTRECT)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
{
|
||||
int[] data = values[i].GetIntVector2().data;
|
||||
data[coordinate] = attrEdit.text.ToInt();
|
||||
values[i] = IntVector2(data);
|
||||
}
|
||||
}
|
||||
else if (type == VAR_INTRECT)
|
||||
{
|
||||
for (uint i = 0; i < values.length; ++i)
|
||||
{
|
||||
int[] data = values[i].GetIntRect().data;
|
||||
data[coordinate] = attrEdit.text.ToInt();
|
||||
values[i] = IntRect(data);
|
||||
String[] data = values[i].ToString().Split(' ');
|
||||
data[coordinate] = String(attrEdit.text.ToInt());
|
||||
values[i] = Variant(type, Join(data, " "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ namespace Urho3D
|
||||
- void SetRandomSeed(uint)
|
||||
- uint GetRandomSeed()
|
||||
- String ToStringHex(int)
|
||||
- String Join(String[]&, const String&)
|
||||
- void ErrorDialog(const String&, const String&)
|
||||
- void OpenConsoleWindow()
|
||||
- String GetConsoleInput()
|
||||
@ -297,6 +298,7 @@ Methods:<br>
|
||||
- bool Contains(const String&) const
|
||||
- bool Contains(uint8) const
|
||||
- String[]@ Split(uint8) const
|
||||
- void Join(String[]&, const String&)
|
||||
- bool ToBool() const
|
||||
- float ToFloat() const
|
||||
- int ToInt() const
|
||||
|
@ -221,32 +221,32 @@ String String::Replaced(const String& replaceThis, const String& replaceWith) co
|
||||
return ret;
|
||||
}
|
||||
|
||||
void String::Append(const String& str)
|
||||
String& String::Append(const String& str)
|
||||
{
|
||||
*this += str;
|
||||
return *this += str;
|
||||
}
|
||||
|
||||
void String::Append(const char* str)
|
||||
String& String::Append(const char* str)
|
||||
{
|
||||
*this += str;
|
||||
return *this += str;
|
||||
}
|
||||
|
||||
void String::Append(char c)
|
||||
String& String::Append(char c)
|
||||
{
|
||||
*this += c;
|
||||
return *this += c;
|
||||
}
|
||||
|
||||
void String::Append(const char* str, unsigned length)
|
||||
String& String::Append(const char* str, unsigned length)
|
||||
{
|
||||
if (!str)
|
||||
return;
|
||||
|
||||
unsigned oldLength = length_;
|
||||
Resize(oldLength + length);
|
||||
CopyChars(&buffer_[oldLength], str, length);
|
||||
if (str)
|
||||
{
|
||||
unsigned oldLength = length_;
|
||||
Resize(oldLength + length);
|
||||
CopyChars(&buffer_[oldLength], str, length);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void String::Insert(unsigned pos, const String& str)
|
||||
{
|
||||
if (pos > length_)
|
||||
@ -474,6 +474,11 @@ Vector<String> String::Split(char separator) const
|
||||
{
|
||||
return Split(CString(), separator);
|
||||
}
|
||||
|
||||
void String::Join(const Vector<String>& subStrings, String glue)
|
||||
{
|
||||
*this = Joined(subStrings, glue);
|
||||
}
|
||||
|
||||
unsigned String::Find(char c, unsigned startPos) const
|
||||
{
|
||||
@ -707,13 +712,13 @@ void String::ReplaceUTF8(unsigned index, unsigned unicodeChar)
|
||||
Replace(beginCharPos, byteOffset - beginCharPos, temp, dest - temp);
|
||||
}
|
||||
|
||||
void String::AppendUTF8(unsigned unicodeChar)
|
||||
String& String::AppendUTF8(unsigned unicodeChar)
|
||||
{
|
||||
char temp[7];
|
||||
char* dest = temp;
|
||||
EncodeUTF8(dest, unicodeChar);
|
||||
*dest = 0;
|
||||
Append(temp);
|
||||
return Append(temp);
|
||||
}
|
||||
|
||||
String String::SubstringUTF8(unsigned pos) const
|
||||
@ -938,15 +943,28 @@ Vector<String> String::Split(const char* str, char separator)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void String::AppendWithFormat(const char* formatString, ... )
|
||||
String String::Joined(const Vector<String>& subStrings, String glue)
|
||||
{
|
||||
if (subStrings.Empty())
|
||||
return String();
|
||||
|
||||
String joinedString(subStrings[0]);
|
||||
for (unsigned i = 1; i < subStrings.Size(); ++i)
|
||||
joinedString.Append(glue).Append(subStrings[i]);
|
||||
|
||||
return joinedString;
|
||||
}
|
||||
|
||||
String& String::AppendWithFormat(const char* formatString, ... )
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, formatString);
|
||||
AppendWithFormatArgs(formatString, args);
|
||||
va_end(args);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void String::AppendWithFormatArgs(const char* formatString, va_list args)
|
||||
String& String::AppendWithFormatArgs(const char* formatString, va_list args)
|
||||
{
|
||||
int pos = 0, lastPos = 0;
|
||||
int length = strlen(formatString);
|
||||
@ -957,7 +975,7 @@ void String::AppendWithFormatArgs(const char* formatString, va_list args)
|
||||
while (pos < length && formatString[pos] != '%') pos++;
|
||||
Append(formatString + lastPos, pos - lastPos);
|
||||
if (pos >= length)
|
||||
return;
|
||||
return *this;
|
||||
|
||||
char arg = formatString[pos + 1];
|
||||
pos += 2;
|
||||
|
@ -278,13 +278,13 @@ public:
|
||||
/// Return a string with all occurrences of a string replaced.
|
||||
String Replaced(const String& replaceThis, const String& replaceWith) const;
|
||||
/// Append a string.
|
||||
void Append(const String& str);
|
||||
String& Append(const String& str);
|
||||
/// Append a C string.
|
||||
void Append(const char* str);
|
||||
String& Append(const char* str);
|
||||
/// Append a character.
|
||||
void Append(char c);
|
||||
String& Append(char c);
|
||||
/// Append characters.
|
||||
void Append(const char* str, unsigned length);
|
||||
String& Append(const char* str, unsigned length);
|
||||
/// Insert a string.
|
||||
void Insert(unsigned pos, const String& str);
|
||||
/// Insert a character.
|
||||
@ -336,6 +336,8 @@ public:
|
||||
String ToLower() const;
|
||||
/// Return substrings split by a separator char.
|
||||
Vector<String> Split(char separator) const;
|
||||
/// Join substrings with a 'glue' string.
|
||||
void Join(const Vector<String>& subStrings, String glue);
|
||||
/// Return index to the first occurrence of a string, or NPOS if not found.
|
||||
unsigned Find(const String& str, unsigned startPos = 0) const;
|
||||
/// Return index to the first occurrence of a character, or NPOS if not found.
|
||||
@ -380,7 +382,7 @@ public:
|
||||
/// Replace Unicode character at index from UTF8 content.
|
||||
void ReplaceUTF8(unsigned index, unsigned unicodeChar);
|
||||
/// Append Unicode character at the end as UTF8.
|
||||
void AppendUTF8(unsigned unicodeChar);
|
||||
String& AppendUTF8(unsigned unicodeChar);
|
||||
/// Return a UTF8 substring from position to end.
|
||||
String SubstringUTF8(unsigned pos) const;
|
||||
/// Return a UTF8 substring with length from position.
|
||||
@ -402,6 +404,8 @@ public:
|
||||
|
||||
/// Return substrings split by a separator char.
|
||||
static Vector<String> Split(const char* str, char separator);
|
||||
/// Return a string by joining substrings with a 'glue' string.
|
||||
static String Joined(const Vector<String>& subStrings, String glue);
|
||||
/// Encode Unicode character to UTF8. Pointer will be incremented.
|
||||
static void EncodeUTF8(char*& dest, unsigned unicodeChar);
|
||||
/// Decode Unicode character from UTF8. Pointer will be incremented.
|
||||
@ -429,9 +433,9 @@ public:
|
||||
}
|
||||
|
||||
/// Append to string using formatting.
|
||||
void AppendWithFormat(const char* formatString, ... );
|
||||
String& AppendWithFormat(const char* formatString, ... );
|
||||
/// Append to string using variable arguments.
|
||||
void AppendWithFormatArgs(const char* formatString, va_list args);
|
||||
String& AppendWithFormatArgs(const char* formatString, va_list args);
|
||||
|
||||
/// Compare two C strings.
|
||||
static int Compare(const char* str1, const char* str2, bool caseSensitive);
|
||||
|
@ -519,7 +519,7 @@ static void RegisterVariant(asIScriptEngine* engine)
|
||||
engine->RegisterObjectMethod("Variant", "String ToString() const", asMETHOD(Variant, ToString), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Variant", "bool IsZero() const", asMETHOD(Variant, IsZero), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Variant", "VariantType get_type() const", asMETHOD(Variant, GetType), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Variant", "const String &get_typeName() const", asMETHODPR(Variant, GetTypeName, () const, const String&), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Variant", "const String& get_typeName() const", asMETHODPR(Variant, GetTypeName, () const, const String&), asCALL_THISCALL);
|
||||
|
||||
engine->RegisterObjectBehaviour("VariantMap", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructVariantMap), asCALL_CDECL_OBJLAST);
|
||||
engine->RegisterObjectBehaviour("VariantMap", asBEHAVE_CONSTRUCT, "void f(const VariantMap&in)", asFUNCTION(ConstructVariantMapCopy), asCALL_CDECL_OBJLAST);
|
||||
@ -544,9 +544,30 @@ static CScriptArray* StringSplit(char separator, const String* str)
|
||||
return VectorToArray<String>(result, "Array<String>");
|
||||
}
|
||||
|
||||
template <class T> Vector<T> ArrayToVector(CScriptArray* arr)
|
||||
{
|
||||
Vector<T> dest(arr->GetSize());
|
||||
for (unsigned i = 0; i < arr->GetSize(); ++i)
|
||||
dest[i] = *static_cast<T*>(arr->At(i));
|
||||
return dest;
|
||||
}
|
||||
|
||||
static void StringJoin(CScriptArray* arr, const String& glue, String* str)
|
||||
{
|
||||
Vector<String> subStrings = ArrayToVector<String>(arr);
|
||||
str->Join(subStrings, glue);
|
||||
}
|
||||
|
||||
static String StringJoined(CScriptArray* arr, const String& glue)
|
||||
{
|
||||
Vector<String> subStrings = ArrayToVector<String>(arr);
|
||||
return String::Joined(subStrings, glue);
|
||||
}
|
||||
|
||||
static void RegisterStringUtils(asIScriptEngine* engine)
|
||||
{
|
||||
engine->RegisterObjectMethod("String", "Array<String>@ Split(uint8) const", asFUNCTION(StringSplit), asCALL_CDECL_OBJLAST);
|
||||
engine->RegisterObjectMethod("String", "void Join(String[]&, const String&in)", asFUNCTION(StringJoin), asCALL_CDECL_OBJLAST);
|
||||
engine->RegisterObjectMethod("String", "bool ToBool() const", asFUNCTIONPR(ToBool, (const String&), bool), asCALL_CDECL_OBJLAST);
|
||||
engine->RegisterObjectMethod("String", "float ToFloat() const", asFUNCTIONPR(ToFloat, (const String&), float), asCALL_CDECL_OBJLAST);
|
||||
engine->RegisterObjectMethod("String", "int ToInt() const", asFUNCTIONPR(ToInt, (const String&), int), asCALL_CDECL_OBJLAST);
|
||||
@ -559,6 +580,7 @@ static void RegisterStringUtils(asIScriptEngine* engine)
|
||||
engine->RegisterObjectMethod("String", "Vector3 ToVector3() const", asFUNCTIONPR(ToVector3, (const String&), Vector3), asCALL_CDECL_OBJLAST);
|
||||
engine->RegisterObjectMethod("String", "Vector4 ToVector4(bool allowMissingCoords = false) const", asFUNCTIONPR(ToVector4, (const String&, bool), Vector4), asCALL_CDECL_OBJFIRST);
|
||||
engine->RegisterGlobalFunction("String ToStringHex(int)", asFUNCTION(ToStringHex), asCALL_CDECL);
|
||||
engine->RegisterGlobalFunction("String Join(String[]&, const String&in glue)", asFUNCTION(StringJoined), asCALL_CDECL);
|
||||
}
|
||||
|
||||
static void ConstructTimer(Timer* ptr)
|
||||
|
Loading…
Reference in New Issue
Block a user