Caret.hpp

This File On Github
Ask A Question

API: latest
module: oatpp
#include "oatpp/core/parser/Caret.hpp"

Caret

Helper class to do parsing operations

namespace oatpp { namespace parser { 
  class Caret {}
}}

Methods

Return Type Name Summary
p_char8 getData Get pointer to a data, passed to Caret constructor
p_char8 getCurrData Same as getData()[position]
v_int32 getDataSize Get size of a data
std::shared_ptr<oatpp::base::StrBuffer> getDataMemoryHandle Get data memoryHandle.
void setPosition Set caret position relative to data
v_int32 getPosition Get caret position relative to data
void setError Set error message and error code.
const char* getErrorMessage Get error message
v_int32 getErrorCode Get error code
bool hasError Check if error is set for the Caret
void clearError Clear error message and error code
Label putLabel Create Label(this);
void inc Multiple implementations:
  1. Increase caret position by one
  2. Increase caret position by amount
bool skipBlankChars Skip chars: [' ', '\t', '\n', '\r','\f']
bool skipChar Skip char
bool findChar Find char. Position will be set to a found char. If
bool skipCharsFromSet Multiple implementations:
  1. Skip chars defined by set.
  2. Skip chars defined by set.
v_int32 findCharFromSet Multiple implementations:
  1. Find one of chars defined by set.
  2. Find one of chars defined by set.
bool findRN Find "\r\n" chars
bool skipRN Skip "\r\n"
bool isAtRN Check if caret at "\r\n" chars
bool findROrN Find '\r' char of '\n' char
bool skipRNOrN if at "\r\n" - skip.
bool skipAllRsAndNs skip any sequence of '\r' and '\n'
long int parseInt parse integer value starting from the current position.
unsigned long int parseUnsignedInt parse integer value starting from the current position.
v_float32 parseFloat32 parse float value starting from the current position.
v_float64 parseFloat64 parse float value starting from the current position.
bool isAtText Multiple implementations:
  1. Check if follows text
  2. Check if follows text
bool isAtTextNCS Multiple implementations:
  1. Check if follows text (Not Case Sensitive)
  2. Check if follows text (Not Case Sensitive)
Label parseStringEnclosed Parse enclosed string.
bool findText Multiple implementations:
  1. Find text and set position to found text
  2. Find text and set position to found text
bool isAtCharFromSet Multiple implementations:
  1. Check if caret is at char defined by set
  2. Check if caret is at char defined by set
bool isAtChar Check if caret is at char
bool isAtBlankChar Check if caret is at one of chars [' ', '\t', '\n', '\r','\f']
bool isAtDigitChar Check if caret is at digit
bool canContinueAtChar Multiple implementations:
  1. Check if caret is at char, and no error is set
  2. Check if caret is at char, and no error is set.
bool canContinue Check if caret position < dataSize and not error is set

Caret::getData

Get pointer to a data, passed to Caret constructor

  • @return

p_char8 getData()

Caret::getCurrData

Same as getData()[position]

  • @return

p_char8 getCurrData()

Caret::getDataSize

Get size of a data

  • @return

v_int32 getDataSize()

Caret::getDataMemoryHandle

Get data memoryHandle.

  • @return

std::shared_ptr<oatpp::base::StrBuffer> getDataMemoryHandle()

Caret::setPosition

Set caret position relative to data

  • @param position

void setPosition(v_int32 position)

Caret::getPosition

Get caret position relative to data

  • @return

v_int32 getPosition()

Caret::setError

Set error message and error code. Note that once error message is set, methods canContinue... will return false

  • @param errorMessage
  • @param errorCode

void setError(const char* errorMessage, v_int32 errorCode = 0)

Caret::getErrorMessage

Get error message

  • @return error message

const char* getErrorMessage()

Caret::getErrorCode

Get error code

  • @return error code

v_int32 getErrorCode()

Caret::hasError

Check if error is set for the Caret

  • @return

bool hasError()

Caret::clearError

Clear error message and error code

void clearError()

Caret::putLabel

Create Label(this);

  • @return Label

Label putLabel()

Caret::inc

  1. Increase caret position by one
    void inc()
    
  2. Increase caret position by amount
    • @param amount
    void inc(v_int32 amount)
    

Caret::skipBlankChars

Skip chars: [' ', '\t', '\n', '\r','\f']

  • @return true if other char found

bool skipBlankChars()

Caret::skipChar

Skip char

  • @param c
  • @return true if other char found

bool skipChar(v_char8 c)

Caret::findChar

Find char. Position will be set to a found char. If no such char found - position will be set to a dataSize;

  • @param c
  • @return true if found

bool findChar(v_char8 c)

Caret::skipCharsFromSet

  1. Skip chars defined by set. ex. skipCharsFromSet("abc") - will skip all 'a', 'b', 'c' chars
    • @param set
    • @return true if other char found
    bool skipCharsFromSet(const char* set)
    
  2. Skip chars defined by set. ex. skipCharsFromSet("abc", 3) - will skip all 'a', 'b', 'c' chars
    • @param set
    • @param setSize
    • @return true if other char found
    bool skipCharsFromSet(p_char8 set, v_int32 setSize)
    

Caret::findCharFromSet

  1. Find one of chars defined by set.
    • @param set
    • @return char found or -1 if no char found
    v_int32 findCharFromSet(const char* set)
    
  2. Find one of chars defined by set.
    • @param set
    • @param setSize
    • @return char found or -1 if no char found
    v_int32 findCharFromSet(p_char8 set, v_int32 setSize)
    

Caret::findRN

Find "\r\n" chars

  • @return true if found

bool findRN()

Caret::skipRN

Skip "\r\n"

  • @return True if position changes. False if caret not at "\r\n"

bool skipRN()

Caret::isAtRN

Check if caret at "\r\n" chars

  • @return

bool isAtRN()

Caret::findROrN

Find '\r' char of '\n' char

  • @return true if found '\r' or '\n'

bool findROrN()

Caret::skipRNOrN

if at "\r\n" - skip. if at "\n" - skip.

  • @return true if position changed

bool skipRNOrN()

Caret::skipAllRsAndNs

skip any sequence of '\r' and '\n'

  • @return true if position changed

bool skipAllRsAndNs()

Caret::parseInt

parse integer value starting from the current position. Using function std::strtol() Warning: position may go out of Caret::getSize() bound.

  • @param base - base is passed to std::strtol function
  • @return parsed value

long int parseInt(int base = 10)

Caret::parseUnsignedInt

parse integer value starting from the current position. Using function std::strtoul() Warning: position may go out of Caret::getSize() bound.

  • @param base - base is passed to std::strtoul function
  • @return parsed value

unsigned long int parseUnsignedInt(int base = 10)

Caret::parseFloat32

parse float value starting from the current position. Using function std::strtof() Warning: position may go out of Caret::getSize() bound.

  • @return parsed value

v_float32 parseFloat32()

Caret::parseFloat64

parse float value starting from the current position. Using function std::strtod() Warning: position may go out of Caret::getSize() bound.

  • @return parsed value

v_float64 parseFloat64()

Caret::isAtText

  1. Check if follows text
    • @param text
    • @param skipIfTrue - increase position if true
    • @return
    bool isAtText(const char* text, bool skipIfTrue = false)
    
  2. Check if follows text
    • @param text
    • @param textSize
    • @param skipIfTrue - increase position if true
    • @return
    bool isAtText(p_char8 text, v_int32 textSize, bool skipIfTrue = false)
    

Caret::isAtTextNCS

  1. Check if follows text (Not Case Sensitive)
    • @param text
    • @param skipIfTrue - increase position if true
    • @return
    bool isAtTextNCS(const char* text, bool skipIfTrue = false)
    
  2. Check if follows text (Not Case Sensitive)
    • @param text
    • @param textSize
    • @param skipIfTrue - increase position if true
    • @return
    bool isAtTextNCS(p_char8 text, v_int32 textSize, bool skipIfTrue = false)
    

Caret::parseStringEnclosed

Parse enclosed string. ex. for data "'let's go'" parseStringEnclosed(''', ''', '\') will return Label to "let's go" without enclosing ''' chars

  • @param openChar
  • @param closeChar
  • @param escapeChar
  • @return

Label parseStringEnclosed(char openChar, char closeChar, char escapeChar)

Caret::findText

  1. Find text and set position to found text
    • @param text
    • @return true if found
    bool findText(const char* text)
    
  2. Find text and set position to found text
    • @param text
    • @param textSize
    • @return true if found
    bool findText(p_char8 text, v_int32 textSize)
    

Caret::isAtCharFromSet

  1. Check if caret is at char defined by set ex. isAtCharFromSet("abc") - will return true for 'a', 'b', 'c' chars
    • @param set
    • @return
    bool isAtCharFromSet(const char* set) const
    
  2. Check if caret is at char defined by set ex. isAtCharFromSet("abc", 3) - will return true for 'a', 'b', 'c' chars
    • @param set
    • @param setSize
    • @return
    bool isAtCharFromSet(p_char8 set, v_int32 setSize) const
    

Caret::isAtChar

Check if caret is at char

  • @param c
  • @return

bool isAtChar(v_char8 c) const

Caret::isAtBlankChar

Check if caret is at one of chars [' ', '\t', '\n', '\r','\f']

  • @return

bool isAtBlankChar() const

Caret::isAtDigitChar

Check if caret is at digit

  • @return

bool isAtDigitChar() const

Caret::canContinueAtChar

  1. Check if caret is at char, and no error is set
    • @param c
    • @return
    bool canContinueAtChar(v_char8 c) const
    
  2. Check if caret is at char, and no error is set. If true inc position by skipChars
    • @param c
    • @param skipChars
    • @return
    bool canContinueAtChar(v_char8 c, v_int32 skipChars)
    

Caret::canContinue

Check if caret position < dataSize and not error is set

  • @return

bool canContinue() const

Caret::Label

Class to label parsing data.

namespace oatpp { namespace parser { 
  class Caret {
    class Label {}
  };
}}

Methods

Return Type Name Summary
[none] Label Constructor.
void start Set current caret position as a starting point for label.
void end Fix current caret position as an end point for label.
p_char8 getData Get pointer to a labeled data.
v_int32 getSize Get size of labeled data.
oatpp::String toString Multiple implementations:
  1. Create oatpp::String from labeled data.
  2. Same astoString(true).
std::string std_str Create std::string from labeled data.

Caret::Label::Label

Constructor.

  • @param caret.

Label(Caret* caret)

Caret::Label::start

Set current caret position as a starting point for label.

void start()

Caret::Label::end

Fix current caret position as an end point for label.

void end()

Caret::Label::getData

Get pointer to a labeled data.

  • @return

p_char8 getData()

Caret::Label::getSize

Get size of labeled data.

  • @return

v_int32 getSize()

Caret::Label::toString

  1. Create oatpp::String from labeled data.
    • @param saveAsOwnData - true - allocate new memory block for string. false - string will point to the same data as label.
    • @return - oatpp::String.
    oatpp::String toString(bool saveAsOwnData)
    
  2. Same astoString(true).
    oatpp::String toString()
    

Caret::Label::std_str

Create std::string from labeled data.

  • @return - std::string.

std::string std_str()

Caret::StateSaveGuard

Caret state saver guard.

namespace oatpp { namespace parser { 
  class Caret {
    class StateSaveGuard {}
  };
}}

Methods

Return Type Name Summary
[none] StateSaveGuard Constructor.
[none] ~StateSaveGuard Destructor. Restore saved state.
v_int32 getSavedPosition Get caret saved position.
const char* getSavedErrorMessage Get caret saved error message.
v_int32 getSavedErrorCode Get caret saved error code.

Caret::StateSaveGuard::StateSaveGuard

Constructor.

  • @param caret.

StateSaveGuard(Caret& caret)

Caret::StateSaveGuard::~StateSaveGuard

Destructor. Restore saved state.

~StateSaveGuard()

Caret::StateSaveGuard::getSavedPosition

Get caret saved position.

  • @return

v_int32 getSavedPosition()

Caret::StateSaveGuard::getSavedErrorMessage

Get caret saved error message.

  • @return

const char* getSavedErrorMessage()

Caret::StateSaveGuard::getSavedErrorCode

Get caret saved error code.

  • @return

v_int32 getSavedErrorCode()