https://github.com/meshula/labtext
A bunch of text processing code
https://github.com/meshula/labtext
Last synced: 8 months ago
JSON representation
A bunch of text processing code
- Host: GitHub
- URL: https://github.com/meshula/labtext
- Owner: meshula
- Created: 2013-06-24T04:21:13.000Z (almost 13 years ago)
- Default Branch: main
- Last Pushed: 2023-10-03T06:47:37.000Z (over 2 years ago)
- Last Synced: 2025-02-01T12:51:12.472Z (over 1 year ago)
- Language: C++
- Size: 85 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
LabText.h is now a single file text parsing utility.
To use LabText.h, include it in your project, and include it at once defining
LABTEXT_ODR to cause the functions to be compiled into your program.
There are two interfaces to LabText; the old char* oriented version, and a new
interface based around a StrView struct. The char* interfaces are deprecated and
will be removed.
StrView is extremely simple, and has no std dependencies or affordances. The
sole purpose of StrView is to represent a non-owning view on a buffer of char.
```cpp
struct StrView
{
char const* curr;
size_t sz;
bool operator==(StrView const& rhs) const
{
return sz == rhs.sz && !strncmp(curr, rhs.curr, sz);
}
bool operator!=(StrView const& rhs) const
{
return !(*this == rhs);
}
};
```
There are several utilities available for StrView. In general, they take a
StrView, and return a new StrView of remaining unprocessed input.
The functions are listed here, and documented only if non-obvious, or if the
return is not a StrView of remaining unprocessed input.
WS, where it appears, is an abbreviation for Whitespace.
Alphanumeric refers to letters and numbers.
```cpp
bool IsEmpty(StrView const& s);
StrView GetToken(StrView s, char delim, StrView& result);
StrView GetTokenWSDelimited(StrView s, char delim, StrView& result);
StrView GetTokenAlphaNumeric(StrView s, StrView& result);
StrView GetTokenAlphaNumericExt(StrView s, char const* additional_characters, StrView& result);
StrView GetString(StrView s, bool recognizeEscapes, StrView& result);
StrView GetInt16(StrView s, int16_t& result);
StrView GetInt32(StrView s, int32_t& result);
StrView GetUInt32(StrView s, uint32_t& result);
StrView GetHex(StrView s, uint32_t& result);
StrView GetFloat(StrView s, float& result);
StrView ScanForCharacter(StrView s, char delim);
StrView ScanBackwardsForCharacter(StrView s, char delim);
StrView ScanForWhiteSpace(StrView s);
StrView ScanBackwardsForWhiteSpace(StrView s);
StrView ScanForNonWhiteSpace(StrView s);
StrView ScanForTrailingNonWhiteSpace(StrView s);
StrView ScanForEndOfLine(StrView s);
StrView ScanForEndOfLine(StrView s, StrView& skipped);
StrView ScanForLastCharacterOnLine(StrView s);
StrView ScanForBeginningOfNextLine(StrView s);
StrView ScanPastCPPComments(StrView s);
StrView SkipCommentsAndWhitespace(StrView s);
StrView Expect(StrView s, StrView expect); // if expect not found return equals s
StrView Strip(StrView s); // strips leading and trailing whitespace
std::vector Split(StrView s, char split);
```