myTinySQL v0.2.0-2-g5000098
A tiny SQL interpreter over fixed-width text files
Loading...
Searching...
No Matches
Functions
Util.cpp File Reference

Implementation of the string helpers declared in Util.hpp. More...

#include "Util.hpp"
#include <algorithm>
#include <cctype>
#include <charconv>

Go to the source code of this file.

Functions

bool tinysql::anonymous_namespace{Util.cpp}::isSpace (char c)
 Tells whether a character is whitespace for trimming.
 
char tinysql::anonymous_namespace{Util.cpp}::upper (unsigned char c)
 Upper-cases one ASCII character.
 
std::string_view tinysql::trimRight (std::string_view text)
 Removes trailing spaces, tabs and line ends.
 
std::string_view tinysql::trim (std::string_view text)
 Removes leading and trailing spaces, tabs and line ends.
 
std::string tinysql::toUpper (std::string_view text)
 Converts ASCII letters to upper case.
 
bool tinysql::equalsIgnoreCase (std::string_view a, std::string_view b)
 Compares two strings, ignoring the case of ASCII letters.
 
bool tinysql::matchesLike (std::string_view text, std::string_view pattern)
 Matches text against an SQL LIKE pattern, ignoring the case of ASCII letters.
 
std::optional< long long > tinysql::parseInteger (std::string_view text)
 Parses a whole string as a base-10 integer.
 

Detailed Description

Implementation of the string helpers declared in Util.hpp.

Definition in file Util.cpp.

Function Documentation

◆ equalsIgnoreCase()

bool tinysql::equalsIgnoreCase ( std::string_view  a,
std::string_view  b 
)

Compares two strings, ignoring the case of ASCII letters.

Parameters
aFirst string.
bSecond string.
Returns
True if a and b are equal apart from upper/lower case.

Definition at line 49 of file Util.cpp.

◆ matchesLike()

bool tinysql::matchesLike ( std::string_view  text,
std::string_view  pattern 
)

Matches text against an SQL LIKE pattern, ignoring the case of ASCII letters.

In the pattern, % stands for any text (also none) and _ for exactly one character; every other character must match itself. For example fran% matches "Francesco" and "FRANCO", and _uigi matches "Luigi". Characters are counted in bytes, so _ does not match an accented letter such as ò, which takes 2 bytes in UTF-8; use % there.

Parameters
textThe text to test.
patternThe pattern.
Returns
True if the whole text matches the whole pattern.

Definition at line 54 of file Util.cpp.

◆ parseInteger()

std::optional< long long > tinysql::parseInteger ( std::string_view  text)

Parses a whole string as a base-10 integer.

Parameters
textThe text to parse; surrounding whitespace and a leading + are allowed.
Returns
The number, or std::nullopt if text is not exactly one integer.

Definition at line 82 of file Util.cpp.

◆ toUpper()

std::string tinysql::toUpper ( std::string_view  text)

Converts ASCII letters to upper case.

Parameters
textThe text to convert.
Returns
An upper-case copy of text.

Definition at line 42 of file Util.cpp.

◆ trim()

std::string_view tinysql::trim ( std::string_view  text)

Removes leading and trailing spaces, tabs and line ends.

Parameters
textThe text to trim; it is not copied.
Returns
A view of text without whitespace at either end.

Definition at line 34 of file Util.cpp.

◆ trimRight()

std::string_view tinysql::trimRight ( std::string_view  text)

Removes trailing spaces, tabs and line ends.

Parameters
textThe text to trim; it is not copied.
Returns
A view of text without its trailing whitespace.

Definition at line 26 of file Util.cpp.