• R/O
  • SSH
  • HTTPS

gtaconfig: Commit


Commit MetaInfo

Revision5 (tree)
Time2017-12-03 08:08:18
Authorquiret

Log Message

- added method to parse specifically typed token in CSyntax
- various improvements

Change Summary

Incremental Difference

--- src/syntax.cpp (revision 4)
+++ src/syntax.cpp (revision 5)
@@ -243,8 +243,40 @@
243243 return numStr;
244244 }
245245
246+const char* CSyntax::ParseTokenOfType(size_t *len, eTokenType expectType, bool parseDirect)
247+{
248+ size_t reset_off = this->GetOffset();
246249
250+ eTokenType tokType;
251+ size_t tokLen;
252+ const char *tok = this->ParseTokenEx( &tokLen, tokType, parseDirect );
247253
254+ if ( !tok )
255+ return NULL;
256+
257+ if ( tokType != expectType )
258+ return NULL;
259+
260+ *len = tokLen;
261+ return tok;
262+}
263+
264+unsigned int CSyntax::TokenToUInt( const char *tok, size_t tokLen )
265+{
266+ //TODO: actually properly implement this.
267+
268+ std::string numStr( tok, tokLen );
269+
270+ try
271+ {
272+ return std::stoul( numStr );
273+ }
274+ catch( std::invalid_argument& )
275+ {
276+ throw bad_format_exception();
277+ }
278+}
279+
248280 bool CSyntax::GetToken(char *buffer, size_t len)
249281 {
250282 size_t size;
@@ -545,7 +577,7 @@
545577 return m_offset;
546578 }
547579
548-void CSyntax::SetOffset(unsigned long offset)
580+void CSyntax::SetOffset(size_t offset)
549581 {
550582 m_offset = offset;
551583 }
--- src/syntax.h (revision 4)
+++ src/syntax.h (revision 5)
@@ -4,6 +4,7 @@
44 //TODO: allow this thing to parse unicode strings aswell using our custom library.
55
66 struct syntax_exception {};
7+struct bad_format_exception {};
78
89 class CSyntax
910 {
@@ -27,7 +28,10 @@
2728 bool IsCurrentNumber(void);
2829 const char* ParseNumber(size_t *len);
2930
31+ const char* ParseTokenOfType(size_t *len, eTokenType expectType, bool parseDirect = false);
32+
3033 static int TokenToInt(const char *tok, size_t tokLen);
34+ static unsigned int TokenToUInt(const char *tok, size_t tokLen);
3135 static double TokenToDouble(const char *tok, size_t tokLen);
3236
3337 bool GetToken(char *buffer, size_t len);
@@ -46,7 +50,7 @@
4650 bool ScanTokenSequence(const char *tokens, bool isDirect, bool caseSensitive);
4751
4852 size_t GetOffset();
49- void SetOffset(unsigned long offset);
53+ void SetOffset(size_t offset);
5054
5155 void Seek(long seek);
5256
Show on old repository browser