Software and Services, Portable Libraries  2019.Mar.01
A library for managing digital certificates
Parse.hpp
Go to the documentation of this file.
1 //
2 // BEGIN_SOFTWARE_AND_SERVICES_COPYRIGHT
3 //
4 // Copyright (C) 2010-2015 Software and Services LLC, All Rights Reserved.
5 //
6 // NOTICE:
7 //
8 // THIS SOURCE CODE BELONGS TO Software and Services LLC.
9 // THIS CODE IS PROPERTY OF THE COPYRIGHT HOLDER AND IS NOT TO
10 // BE DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED WRITTEN
11 // AUTHORIZATION FROM THE OWNER.
12 //
13 // THIS SOFTWARE AND MANUAL ARE BOTH PROTECTED BY UNITED STATES
14 // COPYRIGHT LAW (TITLE 17 UNITED STATES CODE). UNAUTHORIZED REPRODUCTION
15 // AND/OR SALE MAY RESULT IN IMPRISONMENT OF UP TO ONE YEAR AND FINES
16 // OF UP TO $100,000 (17 USC 506). COPYRIGHT INFRINGERS MAY ALSO
17 // BE SUBJECT TO CIVIL LIABILITY.
18 //
19 // THIS NOTICE AND THE ABOVE COPYRIGHT NOTICE MUST REMAIN IN ALL
20 // COPIES AND ANY DERIVED WORK.
21 //
22 // ALL OF THIS CODE IS ORIGINAL WORK BY THE COPYRIGHT HOLDER.
23 //
24 // THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN IS
25 // PROVIDED ON AN "AS IS" BASIS AND Software and Services LLC.
26 // DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
27 // NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
28 // HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
29 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
30 // PURPOSE.
31 //
32 // END_SOFTWARE_AND_SERVICES_COPYRIGHT
33 //
34 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 //+ +
36 //+ NOTE: +
37 //+ ======= +
38 //+ +
39 //+ THIS PARSER works in WCHAR_T ONLY. +
40 //+ Data accepted that is (char*) is converted as needed. +
41 //+ This is done so that L18N data can be parsed. +
42 //+ +
43 //+ The DEFAULT AND ASSUMED INPUT CHARST is en_US.UTF-8 . +
44 //+ The DEFAULT AND ASSUMED OUTPUT CHARST is en_US.UTF-8 . +
45 //+ +
46 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
47 //
48 
62 #ifndef SOFTWARE_AND_SERVICES_LIBRARY_COMMON_PARSE_HPP_
63 #define SOFTWARE_AND_SERVICES_LIBRARY_COMMON_PARSE_HPP_
64 
65 #ifdef WIN32
66 #pragma warning (disable : 4251)
67 #endif
68 
69 #ifdef BUILDING_SAS_COMMON_LIBRARY
70 #include "osver.h"
71 #include "instance.hpp"
72 #include "File.hpp"
73 #include "String.hpp"
74 #else
75 #include <SaS/Common/osver.h>
76 #include <SaS/Common/instance.hpp>
77 #include <SaS/Common/File.hpp>
78 #include <SaS/Common/String.hpp>
79 #endif
80 
81 #ifndef EXPORT_COMMON
82 #ifdef BUILDING_SAS_COMMON_LIBRARY
83 #define EXPORT_COMMON EXPORT_OUT
84 #else
85 #define EXPORT_COMMON EXPORT_IN
86 #endif
87 #endif
88 
89 #include <stdio.h>
90 
91 namespace SoftwareAndServices
92 {
93  namespace Library
94  {
95  namespace Common
96  {
97 
102  class EXPORT_COMMON Parse
103  : virtual public instance<Parse>
104  {
105  public:
106 
110  static const char * utf8;
111 
119  enum charWidth_t {
120 
122  UnknownCharWidth_t = 0,
123 
125  MultibyteCharWidth_t = 1,
126 
128  WideCharWidth_t = 2,
129 
131  BinaryData_t = 3
132  };
133 
139  Parse(charWidth_t mode);
140 
160  Parse(const int fd,
161  const char * filename,
162  charWidth_t mode,
163  const char * iCharset = nullptr,
164  const char * oCharset = nullptr);
165 
182  Parse(const char * buffer,
183  charWidth_t mode,
184  const char * iCharset = nullptr,
185  const char * oCharset = nullptr);
186 
203  Parse(const wchar_t * buffer,
204  charWidth_t mode,
205  const char * iCharset = nullptr,
206  const char * oCharset = nullptr);
207 
224  Parse(File * file,
225  charWidth_t mode,
226  const char * iCharset = nullptr,
227  const char * oCharset = nullptr);
228 
232  virtual ~Parse();
233 
241  bool SetMode(charWidth_t Width);
242 
246  charWidth_t GetMode() const;
247 
255  bool SetInputCharset(const char * charset);
256 
260  const char * GetInputCharset() const;
261 
269  bool SetOutputCharset(const char * charset);
270 
274  const char * GetOutputCharset() const;
275 
293  bool Open(const char * file,
294  int rwMode,
295  charWidth_t charMode,
296  const char * iCharset = nullptr,
297  const char * oCharset = nullptr);
298 
310  size_t CheckAccept(const String & accept) const;
311 
323  size_t CheckAccept(const wchar_t * accept) const;
324 
336  size_t CheckAccept(const char * accept) const;
337 
348  size_t CheckReject(const String & reject) const;
349 
360  size_t CheckReject(const wchar_t * reject) const;
361 
372  size_t CheckReject(const char * reject) const;
373 
374  // How many of the next characters are of type int.
375  // Does not increment dot.
376  //
377  size_t CheckInt() const;
378 
385  size_t CheckDouble() const;
386 
395  size_t Skip(size_t count) const;
396 
405  size_t SkipUntil(const String & term) const;
406 
415  size_t SkipUntil(const wchar_t * term) const;
416 
425  size_t SkipUntil(const char * term) const;
426 
437  String * GetUntil(const String & term) const;
438 
449  String * GetUntil(const wchar_t * term) const;
450 
461  String * GetUntil(const char * term) const;
462 
474  String * GetUntilRegex(const String & term) const;
475 
487  String * GetUntilRegex(const wchar_t * term) const;
488 
500  String * GetUntilRegex(const char * term) const;
501 
513  String * LookUntil(const char * term) const;
514 
526  String * LookUntil(const String & term) const;
527 
538  String * SkipWhile(const char * ToSkip);
539 
550  String * SkipWhileNot(const char * ToSkip);
551 
558  String * GetCount(size_t count) const;
559 
566  String * LookCount(size_t count) const;
567 
576  bool GetDouble(double & results) const;
577 
586  bool GetInt(int & results) const;
587 
591  bool IsEof() const;
592 
596  operator char() const;
597 
601  operator wchar_t() const;
602 
608  bool operator==(const char c) const;
609 
615  bool operator==(const wchar_t c) const;
616 
617 
623  bool operator!=(const char c) const;
624 
630  bool operator!=(const wchar_t c) const;
631 
637  String * GetEntireBuffer() const;
638 
648  bool Ncmp(const char * CompareTo,
649  unsigned int HowManyCharacters) const;
650 
660  bool Ncasecmp(const char * CompareTo,
661  unsigned int HowManyCharacters) const;
662 
663  protected:
664 
665  private:
666  void _Init(charWidth_t mode,
667  const char * iCharset,
668  const char * oCharset);
669 
678  int _AppendToBuf(unsigned int More) const;
679 
680  mutable File * _File;
681 
682  charWidth_t _inputWidth;
683 
684  //mutable const wchar_t * _wPtr;
685  //mutable const char * _cPtr;
686  //mutable size_t _charCount; // Character count
687  //mutable size_t _octetCount; // Octet count.
688 
692  const char * _Icharset;
693 
697  const char * _Ocharset;
698 
702  const char * _applicationCharset;
703 
708  mutable String _LookAheadBuf;
709 
710  };
711 
712  }
713  }
714 }
715 
716 #endif//SOFTWARE_AND_SERVICES_LIBRARY_COMMON_PARSE_HPP_
Like &#39;FILE&#39;, except C++ implementation and allows sockets and disk files to use same object on WINDOW...
Definition: File.hpp:150
Generic buffered IO.
charWidth_t
The difference between UnknownCharWidth_t and BinaryData_t is that BinaryData_t will always process i...
Definition: Parse.hpp:119
Generic text parsing routines.
Definition: Parse.hpp:102
static const char * utf8
The default INPUT and OUTPUT parser charset.
Definition: Parse.hpp:110
Instance counting and tracking.
Definition: instance.hpp:90
This is a class that allows:
Definition: String.hpp:114
Copyright Douglas Mark Royer DouglasRoyer@gmail.com.
Definition: Base.hpp:98
Base class for instance counting objects.
"<SaS/Common/psver.h>" Definitions specific to various OS&#39;s and OS versions.
"<SaS/Common/String.hpp>"String manipulation routines for C++