OpenTTD Source 20250518-master-g9bbc525e53
string_func.cpp File Reference

Test functionality from string_func. More...

#include "../stdafx.h"
#include "../3rdparty/catch2/catch.hpp"
#include "../string_func.h"
#include "../strings_func.h"
#include "../core/string_builder.hpp"
#include "../core/string_consumer.hpp"
#include "../table/control_codes.h"
#include "table/strings.h"
#include "../safeguards.h"

Go to the source code of this file.

Functions

 TEST_CASE ("StrCompareIgnoreCase - std::string")
 
 TEST_CASE ("StrCompareIgnoreCase - std::string_view")
 
 TEST_CASE ("StrEqualsIgnoreCase - std::string")
 
 TEST_CASE ("StrEqualsIgnoreCase - std::string_view")
 
 TEST_CASE ("StrStartsWithIgnoreCase - std::string")
 
 TEST_CASE ("StrStartsWithIgnoreCase - std::string_view")
 
 TEST_CASE ("StrEndsWithIgnoreCase - std::string")
 
 TEST_CASE ("StrEndsWithIgnoreCase - std::string_view")
 
 TEST_CASE ("FormatArrayAsHex")
 
 TEST_CASE ("ConvertHexToBytes")
 
 TEST_CASE ("StrTrimInPlace")
 
 TEST_CASE ("StrTrimView")
 
void FixSCCEncoded (std::string &str, bool fix_code)
 Scan the string for old values of SCC_ENCODED and fix it to it's new, value.
 
static std::string FixSCCEncodedWrapper (const std::string &str, bool fix_code)
 
static void ComposePart (StringBuilder &builder, char32_t c)
 
static void ComposePart (StringBuilder &builder, const std::string &value)
 
template<typename... Args>
static std::string Compose (Args &&... args)
 
 TEST_CASE ("FixSCCEncoded")
 
void FixSCCEncodedNegative (std::string &str)
 Scan the string for SCC_ENCODED_NUMERIC with negative values, and reencode them as uint64_t.
 
static std::string FixSCCEncodedNegativeWrapper (const std::string &str)
 
 TEST_CASE ("FixSCCEncodedNegative")
 
 TEST_CASE ("EncodedString::ReplaceParam - positive")
 
 TEST_CASE ("EncodedString::ReplaceParam - negative")
 

Variables

static const std::vector< std::pair< std::string, std::string > > _str_trim_testcases
 

Detailed Description

Test functionality from string_func.

Definition in file string_func.cpp.

Function Documentation

◆ Compose()

template<typename... Args>
static std::string Compose ( Args &&...  args)
static

Definition at line 352 of file string_func.cpp.

◆ ComposePart() [1/2]

static void ComposePart ( StringBuilder builder,
char32_t  c 
)
static

Definition at line 339 of file string_func.cpp.

◆ ComposePart() [2/2]

static void ComposePart ( StringBuilder builder,
const std::string &  value 
)
static

Definition at line 345 of file string_func.cpp.

◆ FixSCCEncoded()

void FixSCCEncoded ( std::string &  str,
bool  fix_code 
)
extern

Scan the string for old values of SCC_ENCODED and fix it to it's new, value.

Note that at the moment this runs, the string has not been validated yet because the validation looks for SCC_ENCODED. If there is something invalid, just bail out and do not continue trying to replace the tokens.

Parameters
strthe string to fix.

Definition at line 921 of file saveload.cpp.

References StringConsumer::AnyBytesLeft(), BaseStringBuilder::PutUtf8(), SCC_ENCODED, SCC_ENCODED_NUMERIC, SCC_ENCODED_STRING, and StringConsumer::TryReadUtf8().

Referenced by SlStdString().

◆ FixSCCEncodedNegative()

void FixSCCEncodedNegative ( std::string &  str)
extern

◆ FixSCCEncodedNegativeWrapper()

static std::string FixSCCEncodedNegativeWrapper ( const std::string &  str)
static

Definition at line 399 of file string_func.cpp.

◆ FixSCCEncodedWrapper()

static std::string FixSCCEncodedWrapper ( const std::string &  str,
bool  fix_code 
)
static

Definition at line 331 of file string_func.cpp.

◆ TEST_CASE() [1/16]

TEST_CASE ( "ConvertHexToBytes"  )

Definition at line 262 of file string_func.cpp.

◆ TEST_CASE() [2/16]

TEST_CASE ( "EncodedString::ReplaceParam - negative"  )

Definition at line 428 of file string_func.cpp.

◆ TEST_CASE() [3/16]

TEST_CASE ( "EncodedString::ReplaceParam - positive"  )

Definition at line 416 of file string_func.cpp.

◆ TEST_CASE() [4/16]

TEST_CASE ( "FixSCCEncoded"  )

Definition at line 360 of file string_func.cpp.

◆ TEST_CASE() [5/16]

TEST_CASE ( "FixSCCEncodedNegative"  )

Definition at line 406 of file string_func.cpp.

◆ TEST_CASE() [6/16]

TEST_CASE ( "FormatArrayAsHex"  )

Definition at line 255 of file string_func.cpp.

◆ TEST_CASE() [7/16]

TEST_CASE ( "StrCompareIgnoreCase - std::string"  )

Definition at line 26 of file string_func.cpp.

◆ TEST_CASE() [8/16]

TEST_CASE ( "StrCompareIgnoreCase - std::string_view"  )

Definition at line 50 of file string_func.cpp.

◆ TEST_CASE() [9/16]

TEST_CASE ( "StrEndsWithIgnoreCase - std::string"  )

Definition at line 194 of file string_func.cpp.

◆ TEST_CASE() [10/16]

TEST_CASE ( "StrEndsWithIgnoreCase - std::string_view"  )

Definition at line 219 of file string_func.cpp.

◆ TEST_CASE() [11/16]

TEST_CASE ( "StrEqualsIgnoreCase - std::string"  )

Definition at line 84 of file string_func.cpp.

◆ TEST_CASE() [12/16]

TEST_CASE ( "StrEqualsIgnoreCase - std::string_view"  )

Definition at line 102 of file string_func.cpp.

◆ TEST_CASE() [13/16]

TEST_CASE ( "StrStartsWithIgnoreCase - std::string"  )

Definition at line 132 of file string_func.cpp.

◆ TEST_CASE() [14/16]

TEST_CASE ( "StrStartsWithIgnoreCase - std::string_view"  )

Definition at line 157 of file string_func.cpp.

◆ TEST_CASE() [15/16]

TEST_CASE ( "StrTrimInPlace"  )

Definition at line 314 of file string_func.cpp.

◆ TEST_CASE() [16/16]

TEST_CASE ( "StrTrimView"  )

Definition at line 322 of file string_func.cpp.

Variable Documentation

◆ _str_trim_testcases

const std::vector<std::pair<std::string, std::string> > _str_trim_testcases
static
Initial value:
= {
{"a", "a"},
{" a", "a"},
{"a ", "a"},
{" a ", "a"},
{" a b c ", "a b c"},
{" ", ""},
{" \r\f\t ", ""},
}

Definition at line 304 of file string_func.cpp.