Blame view

3rdparty/boost_1_81_0/libs/json/test/make-pvs.py 2.32 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  # Build test vector variable
  
  import os
  
  def chex(c):
      d1 = ord(c)/16;
      d2 = ord(c)%16;
      d = "0123456789ABCDEF";
      s = "\\x" + d[d1:d1+1] + d[d2:d2+1];
      return s;
  
  def escape(c):
      if c == ' ' or c == '\t':
          return c;
      elif c == '\"':
          return "\\\"";
      elif c == '\\':
          return "\\\\";
      n = ord(c);
      if n >= 32 and n <= 127:
          return c;
      return chex(c) + "\"\"";
  
  def tocpp(s):
      v0 = ""
      v = "\"";
      for c in s:
          v = v + escape(c);
          if len(v) > 80:
              if len(v0) > 50000:
                  return v0 + v + "\"";
              v0 += v + "\"\n               \"";
              v = "";
      return v0 + v + "\"";
  
  def do_files(directory):
      for root, directories, files in os.walk(directory):
          for filename in files:
              filepath = os.path.join(root, filename)
              with open(filepath, 'r') as file:
                  data = file.read();
                  print("        { '" + filename[0:1] + "', \"" + filename[2:-5] + "\", lit(" + tocpp(data) + ") },");
  
  print("""
  //
  // Copyright (c) 2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  //
  // Distributed under the Boost Software License, Version 1.0. (See accompanying
  // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  //
  // Official repository: https://github.com/boostorg/json
  //
  
  #ifndef PARSE_VECTORS
  #define PARSE_VECTORS
  
  #include <boost/utility/string_view.hpp>
  #include <cstdlib>
  #include <type_traits>
  
  struct parse_vectors
  {
      struct item
      {
          char result;
          ::boost::string_view name;
          ::boost::string_view text;
      };
  
      using iterator = item const*;
  
      iterator begin() const noexcept
      {
          return first_;
      }
  
      iterator end() const noexcept
      {
          return last_;
      }
  
      std::size_t
      size() const noexcept
      {
          return last_ - first_;
      }
  
      inline parse_vectors() noexcept;
  
  private:
      template<std::size_t N>
      static
      ::boost::string_view
      lit(char const (&s)[N])
      {
          return {s, N - 1};
      }
  
      iterator first_;
      iterator last_;
  };
  
  parse_vectors::
  parse_vectors() noexcept
  {
      static item const list[] = {""");
  
  do_files("parse-vectors");
  
  print("""        { ' ', "", "" }
      };
      first_ = &list[0];
      last_ = &list[std::extent<
          decltype(list)>::value - 1];
  }
  
  #endif""");