1 /******************************************************************************
2  * $Id: cplkeywordparser.h c39d156816d937c3139360b11786c769aeabd21e 2018-05-05 19:48:08 +0200 Even Rouault $
3  *
4  * Project:  Common Portability Library
5  * Purpose:  Implementation of CPLKeywordParser - a class for parsing
6  *           the keyword format used for files like QuickBird .RPB files.
7  *           This is a slight variation on the NASAKeywordParser used for
8  *           the PDS/ISIS2/ISIS3 formats.
9  * Author:   Frank Warmerdam <warmerdam@pobox.com
10  *
11  ******************************************************************************
12  * Copyright (c) 2008, Frank Warmerdam <warmerdam@pobox.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included
22  * in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  ****************************************************************************/
32 
33 #ifndef CPL_KEYWORD_PARSER
34 #define CPL_KEYWORD_PARSER
35 
36 #include "cpl_string.h"
37 
38 /************************************************************************/
39 /* ==================================================================== */
40 /*                          CPLKeywordParser                          */
41 /* ==================================================================== */
42 /************************************************************************/
43 
44 /*! @cond Doxygen_Suppress */
45 
46 class CPLKeywordParser
47 {
48     char     **papszKeywordList = nullptr;
49 
50     CPLString osHeaderText{};
51     const char *pszHeaderNext = nullptr;
52 
53     void    SkipWhite();
54     bool    ReadWord( CPLString &osWord );
55     bool    ReadPair( CPLString &osName, CPLString &osValue );
56     bool    ReadGroup( const char *pszPathPrefix, int nRecLevel );
57 
58     CPL_DISALLOW_COPY_ASSIGN(CPLKeywordParser)
59 
60 public:
61     CPLKeywordParser();
62     ~CPLKeywordParser();
63 
64     int     Ingest( VSILFILE *fp );
65 
66     const char *GetKeyword( const char *pszPath, const char *pszDefault=nullptr );
GetAllKeywords()67     char  **GetAllKeywords() { return papszKeywordList; }
68 };
69 
70 /*! @endcond */
71 
72 #endif /* def CPL_KEYWORD_PARSER */
73