Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Classes | Functions
String Utilities

String utilities. More...

Classes

struct  gf::CodepointRange
 A range over a sequence of codepoints in UTF-8. More...
 
struct  gf::CodepointRange::Iterator
 Iterator for a range of codepoints. More...
 

Functions

GF_CORE_API std::string gf::niceNum (float num, float precision)
 Create a string representation of a floating point number. More...
 
GF_CORE_API std::string gf::formatString (const char *fmt,...)
 Format a string like printf. More...
 
GF_CORE_API std::string gf::formatString (const char *fmt, va_list ap)
 Format a string like vprintf. More...
 
GF_CORE_API std::string gf::escapeString (std::string_view str)
 Escape a string. More...
 
GF_CORE_API std::vector< std::string_view > gf::splitInParagraphs (std::string_view str)
 Split a string in multiples paragraphs. More...
 
GF_CORE_API std::vector< std::string_view > gf::splitInWords (std::string_view str)
 Split a string in multiples words. More...
 

Detailed Description

String utilities.

Function Documentation

◆ escapeString()

GF_CORE_API std::string gf::escapeString ( std::string_view  str)

Escape a string.

This function replaces characters with their escaped equivalent. For example, a '\n' character is replaced with "\\\\n". This function can be used to display strings.

Parameters
strThe input string
Returns
An escaped string

◆ formatString() [1/2]

GF_CORE_API std::string gf::formatString ( const char *  fmt,
va_list  ap 
)

Format a string like vprintf.

Parameters
fmtThe format string
apThe arguments of the format string

◆ formatString() [2/2]

GF_CORE_API std::string gf::formatString ( const char *  fmt,
  ... 
)

Format a string like printf.

Parameters
fmtThe format string

◆ niceNum()

GF_CORE_API std::string gf::niceNum ( float  num,
float  precision 
)

Create a string representation of a floating point number.

It is based on Python niceNum.

Parameters
numThe number to display
precisionThe precision to use for display
Returns
A string representing the number

◆ splitInParagraphs()

GF_CORE_API std::vector< std::string_view > gf::splitInParagraphs ( std::string_view  str)

Split a string in multiples paragraphs.

The paragraphs are separated by '\n'.

Parameters
strThe input string
Returns
A vector of strings containing the paragraphs

◆ splitInWords()

GF_CORE_API std::vector< std::string_view > gf::splitInWords ( std::string_view  str)

Split a string in multiples words.

The words are separated by ' ' (space) or '\t' (tabulation).

Parameters
strThe input string
Returns
A vector of strings containing the words