From fa85812a4787d4c358aeaa467151cbb55fd56c6b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 13 Feb 2013 18:44:19 -0500 Subject: [PATCH] Fix problems with age display name formatting - Age User Name and Age Instance Name are equal in the case of some child and public ages. If they are, only return one of them. Don't return "Ae'gura Ae'gura" - Changed to return plString instead of a pointer to a temporary buffer that immediately goes out of scope --- .../FeatureLib/pfPython/pyAgeInfoStruct.cpp | 40 +++++++++++++------ .../FeatureLib/pfPython/pyAgeInfoStruct.h | 4 +- .../pfPython/pyAgeInfoStructGlue.cpp | 4 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp index 5b0708ec..4cdfa0b7 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp @@ -178,14 +178,22 @@ void pyAgeInfoStruct::SetAgeLanguage( int32_t v ) fAgeInfo.SetAgeLanguage( v ); } -const char * pyAgeInfoStruct::GetDisplayName() const +plString pyAgeInfoStruct::GetDisplayName() const { - int32_t seq = GetAgeSequenceNumber(); - if ( seq>0 ) - fDisplayName = plString::Format( "%s (%d) %s", GetAgeUserDefinedName(), seq, GetAgeInstanceName() ); + const char* instance = GetAgeInstanceName(); + const char* user = GetAgeUserDefinedName(); + bool namesEqual = (stricmp(user, instance) == 0); // Ae'gura Ae'gura + + if (namesEqual) + return instance; else - fDisplayName = plString::Format( "%s %s", GetAgeUserDefinedName(), GetAgeInstanceName() ); - return fDisplayName.c_str(); + { + int32_t seq = GetAgeSequenceNumber(); + if (seq > 0) + return plString::Format("%s (%d) %s", user, seq, instance); + else + return plString::Format("%s %s", user, instance); + } } @@ -255,12 +263,20 @@ void pyAgeInfoStructRef::SetAgeSequenceNumber( int32_t v ) fAgeInfo.SetAgeSequenceNumber( v ); } -const char * pyAgeInfoStructRef::GetDisplayName() const +plString pyAgeInfoStructRef::GetDisplayName() const { - int32_t seq = GetAgeSequenceNumber(); - if ( seq>0 ) - fDisplayName = plString::Format( "%s (%d) %s", GetAgeUserDefinedName(), seq, GetAgeInstanceName() ); + const char* instance = GetAgeInstanceName(); + const char* user = GetAgeUserDefinedName(); + bool namesEqual = (stricmp(user, instance) == 0); // Ae'gura Ae'gura + + if (namesEqual) + return instance; else - fDisplayName = plString::Format( "%s %s", GetAgeUserDefinedName(), GetAgeInstanceName() ); - return fDisplayName.c_str(); + { + int32_t seq = GetAgeSequenceNumber(); + if (seq > 0) + return plString::Format("%s (%d) %s", user, seq, instance); + else + return plString::Format("%s %s", user, instance); + } } diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h index d28ab403..89a7d302 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h @@ -101,7 +101,7 @@ public: void SetAgeSequenceNumber( int32_t v ); int32_t GetAgeLanguage() const; void SetAgeLanguage( int32_t v ); - const char * GetDisplayName() const; + plString GetDisplayName() const; }; class pyAgeInfoStructRef @@ -142,7 +142,7 @@ public: void SetAgeInstanceGuid( const char * guid ); int32_t GetAgeSequenceNumber() const; void SetAgeSequenceNumber( int32_t v ); - const char * GetDisplayName() const; + plString GetDisplayName() const; }; #endif // pyAgeInfoStruct_h_inc diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp index 1b03f826..fad2a201 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp @@ -234,7 +234,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeLanguage, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStruct, getDisplayName) { - return PyString_FromString(self->fThis->GetDisplayName()); + return PyString_FromPlString(self->fThis->GetDisplayName()); } PYTHON_START_METHODS_TABLE(ptAgeInfoStruct) @@ -410,7 +410,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStructRef, setAgeSequenceNumber, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStructRef, getDisplayName) { - return PyString_FromString(self->fThis->GetDisplayName()); + return PyString_FromPlString(self->fThis->GetDisplayName()); } PYTHON_START_METHODS_TABLE(ptAgeInfoStructRef)