scanscalar.h 2.18 KB
Newer Older
1
2
3
#ifndef SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

Jesse Beder's avatar
Jesse Beder committed
4
5
6
#if defined(_MSC_VER) ||                                            \
    (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
     (__GNUC__ >= 4))  // GCC supports "pragma once" correctly since 3.4
7
8
9
#pragma once
#endif

10
#include <string>
Jesse Beder's avatar
Jesse Beder committed
11

12
#include "regex_yaml.h"
13
14
#include "stream.h"

Jesse Beder's avatar
Jesse Beder committed
15
namespace YAML {
Jesse Beder's avatar
Jesse Beder committed
16
17
18
enum CHOMP { STRIP = -1, CLIP, KEEP };
enum ACTION { NONE, BREAK, THROW };
enum FOLD { DONT_FOLD, FOLD_BLOCK, FOLD_FLOW };
Jesse Beder's avatar
Jesse Beder committed
19
20
21

struct ScanScalarParams {
  ScanScalarParams()
22
23
      : end(nullptr),
        eatEnd(false),
Jesse Beder's avatar
Jesse Beder committed
24
25
26
27
28
29
30
31
32
33
        indent(0),
        detectIndent(false),
        eatLeadingWhitespace(0),
        escape(0),
        fold(DONT_FOLD),
        trimTrailingSpaces(0),
        chomp(CLIP),
        onDocIndicator(NONE),
        onTabInIndentation(NONE),
        leadingSpaces(false) {}
34

Jesse Beder's avatar
Jesse Beder committed
35
  // input:
36
37
  const RegEx* end;   // what condition ends this scalar?
                      // unowned.
Jesse Beder's avatar
Jesse Beder committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  bool eatEnd;        // should we eat that condition when we see it?
  int indent;         // what level of indentation should be eaten and ignored?
  bool detectIndent;  // should we try to autodetect the indent?
  bool eatLeadingWhitespace;  // should we continue eating this delicious
                              // indentation after 'indent' spaces?
  char escape;  // what character do we escape on (i.e., slash or single quote)
                // (0 for none)
  FOLD fold;    // how do we fold line ends?
  bool trimTrailingSpaces;  // do we remove all trailing spaces (at the very
                            // end)
  CHOMP chomp;  // do we strip, clip, or keep trailing newlines (at the very
                // end)
  //   Note: strip means kill all, clip means keep at most one, keep means keep
  // all
  ACTION onDocIndicator;      // what do we do if we see a document indicator?
  ACTION onTabInIndentation;  // what do we do if we see a tab where we should
                              // be seeing indentation spaces

  // output:
  bool leadingSpaces;
};

60
std::string ScanScalar(Stream& INPUT, ScanScalarParams& params);
Jesse Beder's avatar
Jesse Beder committed
61
}
62

Jesse Beder's avatar
Jesse Beder committed
63
#endif  // SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66