calamares/src/libcalamares/locale/TranslatableString.cpp
Adriaan de Groot 1cd9b93a22 REUSE: Giant boilerplate cleanup
- point to main Calamares site in the 'part of' headers instead
  of to github (this is the "this file is part of Calamares"
  opening line for most files).
- remove boilerplate from all source files, CMake modules and completions,
  this is the 3-paragraph summary of the GPL-3.0-or-later, which has
  a meaning entirely covered by the SPDX tag.
2020-08-26 02:28:38 +02:00

80 lines
1.5 KiB
C++

/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*
*/
#include "TranslatableString.h"
/** @brief Massage an identifier into a human-readable form
*
* Makes a copy of @p s, caller must free() it.
*/
static char*
munge( const char* s )
{
char* t = strdup( s );
if ( !t )
{
return nullptr;
}
// replace("_"," ") in the Python script
char* p = t;
while ( *p )
{
if ( ( *p ) == '_' )
{
*p = ' ';
}
++p;
}
return t;
}
namespace CalamaresUtils
{
namespace Locale
{
TranslatableString::TranslatableString( TranslatableString&& t )
: m_human( nullptr )
, m_key()
{
// My pointers are initialized to nullptr
std::swap( m_human, t.m_human );
std::swap( m_key, t.m_key );
}
TranslatableString::TranslatableString( const TranslatableString& t )
: m_human( t.m_human ? strdup( t.m_human ) : nullptr )
, m_key( t.m_key )
{
}
TranslatableString::TranslatableString( const char* s1 )
: m_human( s1 ? munge( s1 ) : nullptr )
, m_key( s1 ? QString( s1 ) : QString() )
{
}
TranslatableString::TranslatableString( const QString& s )
: m_human( munge( s.toUtf8().constData() ) )
, m_key( s )
{
}
TranslatableString::~TranslatableString()
{
free( m_human );
}
} // namespace Locale
} // namespace CalamaresUtils