duckdb 0.4.1-dev439.0 → 0.4.1-dev454.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "dc7a5ccc5"
15
- #define DUCKDB_VERSION "v0.4.1-dev439"
14
+ #define DUCKDB_SOURCE_ID "dd62fd774"
15
+ #define DUCKDB_VERSION "v0.4.1-dev454"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -22956,6 +22956,8 @@ struct BufferedCSVReaderOptions {
22956
22956
  //! Whether file is compressed or not, and if so which compression type
22957
22957
  //! AUTO_DETECT (default; infer from file extension)
22958
22958
  FileCompressionType compression = FileCompressionType::AUTO_DETECT;
22959
+ //! The column names of the columns to read/write
22960
+ vector<string> names;
22959
22961
 
22960
22962
  //===--------------------------------------------------------------------===//
22961
22963
  // ReadCSVOptions
@@ -22982,13 +22984,13 @@ struct BufferedCSVReaderOptions {
22982
22984
  string file_path;
22983
22985
  //! Whether or not to include a file name column
22984
22986
  bool include_file_name = false;
22987
+ //! Whether or not to include a parsed hive partition columns
22988
+ bool include_parsed_hive_partitions = false;
22985
22989
 
22986
22990
  //===--------------------------------------------------------------------===//
22987
22991
  // WriteCSVOptions
22988
22992
  //===--------------------------------------------------------------------===//
22989
22993
 
22990
- //! The column names of the columns to write
22991
- vector<string> names;
22992
22994
  //! True, if column with that index must be quoted
22993
22995
  vector<bool> force_quote;
22994
22996
 
@@ -23212,6 +23214,1223 @@ public:
23212
23214
  string ToString(const string &column_name) override;
23213
23215
  };
23214
23216
 
23217
+ } // namespace duckdb
23218
+ //===----------------------------------------------------------------------===//
23219
+ // DuckDB
23220
+ //
23221
+ // duckdb/common/hive_partitioning.hpp
23222
+ //
23223
+ //
23224
+ //===----------------------------------------------------------------------===//
23225
+
23226
+
23227
+
23228
+
23229
+
23230
+ // LICENSE_CHANGE_BEGIN
23231
+ // The following code up to LICENSE_CHANGE_END is subject to THIRD PARTY LICENSE #1
23232
+ // See the end of this file for a list
23233
+
23234
+ // Copyright 2003-2009 The RE2 Authors. All Rights Reserved.
23235
+ // Use of this source code is governed by a BSD-style
23236
+ // license that can be found in the LICENSE file.
23237
+
23238
+ #ifndef RE2_RE2_H_
23239
+ #define RE2_RE2_H_
23240
+
23241
+ // C++ interface to the re2 regular-expression library.
23242
+ // RE2 supports Perl-style regular expressions (with extensions like
23243
+ // \d, \w, \s, ...).
23244
+ //
23245
+ // -----------------------------------------------------------------------
23246
+ // REGEXP SYNTAX:
23247
+ //
23248
+ // This module uses the re2 library and hence supports
23249
+ // its syntax for regular expressions, which is similar to Perl's with
23250
+ // some of the more complicated things thrown away. In particular,
23251
+ // backreferences and generalized assertions are not available, nor is \Z.
23252
+ //
23253
+ // See https://github.com/google/re2/wiki/Syntax for the syntax
23254
+ // supported by RE2, and a comparison with PCRE and PERL regexps.
23255
+ //
23256
+ // For those not familiar with Perl's regular expressions,
23257
+ // here are some examples of the most commonly used extensions:
23258
+ //
23259
+ // "hello (\\w+) world" -- \w matches a "word" character
23260
+ // "version (\\d+)" -- \d matches a digit
23261
+ // "hello\\s+world" -- \s matches any whitespace character
23262
+ // "\\b(\\w+)\\b" -- \b matches non-empty string at word boundary
23263
+ // "(?i)hello" -- (?i) turns on case-insensitive matching
23264
+ // "/\\*(.*?)\\*/" -- .*? matches . minimum no. of times possible
23265
+ //
23266
+ // -----------------------------------------------------------------------
23267
+ // MATCHING INTERFACE:
23268
+ //
23269
+ // The "FullMatch" operation checks that supplied text matches a
23270
+ // supplied pattern exactly.
23271
+ //
23272
+ // Example: successful match
23273
+ // CHECK(RE2::FullMatch("hello", "h.*o"));
23274
+ //
23275
+ // Example: unsuccessful match (requires full match):
23276
+ // CHECK(!RE2::FullMatch("hello", "e"));
23277
+ //
23278
+ // -----------------------------------------------------------------------
23279
+ // UTF-8 AND THE MATCHING INTERFACE:
23280
+ //
23281
+ // By default, the pattern and input text are interpreted as UTF-8.
23282
+ // The RE2::Latin1 option causes them to be interpreted as Latin-1.
23283
+ //
23284
+ // Example:
23285
+ // CHECK(RE2::FullMatch(utf8_string, RE2(utf8_pattern)));
23286
+ // CHECK(RE2::FullMatch(latin1_string, RE2(latin1_pattern, RE2::Latin1)));
23287
+ //
23288
+ // -----------------------------------------------------------------------
23289
+ // MATCHING WITH SUBSTRING EXTRACTION:
23290
+ //
23291
+ // You can supply extra pointer arguments to extract matched substrings.
23292
+ // On match failure, none of the pointees will have been modified.
23293
+ // On match success, the substrings will be converted (as necessary) and
23294
+ // their values will be assigned to their pointees until all conversions
23295
+ // have succeeded or one conversion has failed.
23296
+ // On conversion failure, the pointees will be in an indeterminate state
23297
+ // because the caller has no way of knowing which conversion failed.
23298
+ // However, conversion cannot fail for types like string and StringPiece
23299
+ // that do not inspect the substring contents. Hence, in the common case
23300
+ // where all of the pointees are of such types, failure is always due to
23301
+ // match failure and thus none of the pointees will have been modified.
23302
+ //
23303
+ // Example: extracts "ruby" into "s" and 1234 into "i"
23304
+ // int i;
23305
+ // std::string s;
23306
+ // CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i));
23307
+ //
23308
+ // Example: fails because string cannot be stored in integer
23309
+ // CHECK(!RE2::FullMatch("ruby", "(.*)", &i));
23310
+ //
23311
+ // Example: fails because there aren't enough sub-patterns
23312
+ // CHECK(!RE2::FullMatch("ruby:1234", "\\w+:\\d+", &s));
23313
+ //
23314
+ // Example: does not try to extract any extra sub-patterns
23315
+ // CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s));
23316
+ //
23317
+ // Example: does not try to extract into NULL
23318
+ // CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", NULL, &i));
23319
+ //
23320
+ // Example: integer overflow causes failure
23321
+ // CHECK(!RE2::FullMatch("ruby:1234567891234", "\\w+:(\\d+)", &i));
23322
+ //
23323
+ // NOTE(rsc): Asking for substrings slows successful matches quite a bit.
23324
+ // This may get a little faster in the future, but right now is slower
23325
+ // than PCRE. On the other hand, failed matches run *very* fast (faster
23326
+ // than PCRE), as do matches without substring extraction.
23327
+ //
23328
+ // -----------------------------------------------------------------------
23329
+ // PARTIAL MATCHES
23330
+ //
23331
+ // You can use the "PartialMatch" operation when you want the pattern
23332
+ // to match any substring of the text.
23333
+ //
23334
+ // Example: simple search for a string:
23335
+ // CHECK(RE2::PartialMatch("hello", "ell"));
23336
+ //
23337
+ // Example: find first number in a string
23338
+ // int number;
23339
+ // CHECK(RE2::PartialMatch("x*100 + 20", "(\\d+)", &number));
23340
+ // CHECK_EQ(number, 100);
23341
+ //
23342
+ // -----------------------------------------------------------------------
23343
+ // PRE-COMPILED REGULAR EXPRESSIONS
23344
+ //
23345
+ // RE2 makes it easy to use any string as a regular expression, without
23346
+ // requiring a separate compilation step.
23347
+ //
23348
+ // If speed is of the essence, you can create a pre-compiled "RE2"
23349
+ // object from the pattern and use it multiple times. If you do so,
23350
+ // you can typically parse text faster than with sscanf.
23351
+ //
23352
+ // Example: precompile pattern for faster matching:
23353
+ // RE2 pattern("h.*o");
23354
+ // while (ReadLine(&str)) {
23355
+ // if (RE2::FullMatch(str, pattern)) ...;
23356
+ // }
23357
+ //
23358
+ // -----------------------------------------------------------------------
23359
+ // SCANNING TEXT INCREMENTALLY
23360
+ //
23361
+ // The "Consume" operation may be useful if you want to repeatedly
23362
+ // match regular expressions at the front of a string and skip over
23363
+ // them as they match. This requires use of the "StringPiece" type,
23364
+ // which represents a sub-range of a real string.
23365
+ //
23366
+ // Example: read lines of the form "var = value" from a string.
23367
+ // std::string contents = ...; // Fill string somehow
23368
+ // StringPiece input(contents); // Wrap a StringPiece around it
23369
+ //
23370
+ // std::string var;
23371
+ // int value;
23372
+ // while (RE2::Consume(&input, "(\\w+) = (\\d+)\n", &var, &value)) {
23373
+ // ...;
23374
+ // }
23375
+ //
23376
+ // Each successful call to "Consume" will set "var/value", and also
23377
+ // advance "input" so it points past the matched text. Note that if the
23378
+ // regular expression matches an empty string, input will advance
23379
+ // by 0 bytes. If the regular expression being used might match
23380
+ // an empty string, the loop body must check for this case and either
23381
+ // advance the string or break out of the loop.
23382
+ //
23383
+ // The "FindAndConsume" operation is similar to "Consume" but does not
23384
+ // anchor your match at the beginning of the string. For example, you
23385
+ // could extract all words from a string by repeatedly calling
23386
+ // RE2::FindAndConsume(&input, "(\\w+)", &word)
23387
+ //
23388
+ // -----------------------------------------------------------------------
23389
+ // USING VARIABLE NUMBER OF ARGUMENTS
23390
+ //
23391
+ // The above operations require you to know the number of arguments
23392
+ // when you write the code. This is not always possible or easy (for
23393
+ // example, the regular expression may be calculated at run time).
23394
+ // You can use the "N" version of the operations when the number of
23395
+ // match arguments are determined at run time.
23396
+ //
23397
+ // Example:
23398
+ // const RE2::Arg* args[10];
23399
+ // int n;
23400
+ // // ... populate args with pointers to RE2::Arg values ...
23401
+ // // ... set n to the number of RE2::Arg objects ...
23402
+ // bool match = RE2::FullMatchN(input, pattern, args, n);
23403
+ //
23404
+ // The last statement is equivalent to
23405
+ //
23406
+ // bool match = RE2::FullMatch(input, pattern,
23407
+ // *args[0], *args[1], ..., *args[n - 1]);
23408
+ //
23409
+ // -----------------------------------------------------------------------
23410
+ // PARSING HEX/OCTAL/C-RADIX NUMBERS
23411
+ //
23412
+ // By default, if you pass a pointer to a numeric value, the
23413
+ // corresponding text is interpreted as a base-10 number. You can
23414
+ // instead wrap the pointer with a call to one of the operators Hex(),
23415
+ // Octal(), or CRadix() to interpret the text in another base. The
23416
+ // CRadix operator interprets C-style "0" (base-8) and "0x" (base-16)
23417
+ // prefixes, but defaults to base-10.
23418
+ //
23419
+ // Example:
23420
+ // int a, b, c, d;
23421
+ // CHECK(RE2::FullMatch("100 40 0100 0x40", "(.*) (.*) (.*) (.*)",
23422
+ // RE2::Octal(&a), RE2::Hex(&b), RE2::CRadix(&c), RE2::CRadix(&d));
23423
+ // will leave 64 in a, b, c, and d.
23424
+
23425
+ #include <stddef.h>
23426
+ #include <stdint.h>
23427
+ #include <algorithm>
23428
+ #include <map>
23429
+ #include <mutex>
23430
+ #include <string>
23431
+
23432
+
23433
+
23434
+ // LICENSE_CHANGE_BEGIN
23435
+ // The following code up to LICENSE_CHANGE_END is subject to THIRD PARTY LICENSE #1
23436
+ // See the end of this file for a list
23437
+
23438
+ // Copyright 2001-2010 The RE2 Authors. All Rights Reserved.
23439
+ // Use of this source code is governed by a BSD-style
23440
+ // license that can be found in the LICENSE file.
23441
+
23442
+ #ifndef RE2_STRINGPIECE_H_
23443
+ #define RE2_STRINGPIECE_H_
23444
+
23445
+ #ifdef min
23446
+ #undef min
23447
+ #endif
23448
+
23449
+ // A string-like object that points to a sized piece of memory.
23450
+ //
23451
+ // Functions or methods may use const StringPiece& parameters to accept either
23452
+ // a "const char*" or a "string" value that will be implicitly converted to
23453
+ // a StringPiece. The implicit conversion means that it is often appropriate
23454
+ // to include this .h file in other files rather than forward-declaring
23455
+ // StringPiece as would be appropriate for most other Google classes.
23456
+ //
23457
+ // Systematic usage of StringPiece is encouraged as it will reduce unnecessary
23458
+ // conversions from "const char*" to "string" and back again.
23459
+ //
23460
+ //
23461
+ // Arghh! I wish C++ literals were "string".
23462
+
23463
+ // Doing this simplifies the logic below.
23464
+ #ifndef __has_include
23465
+ #define __has_include(x) 0
23466
+ #endif
23467
+
23468
+ #include <stddef.h>
23469
+ #include <string.h>
23470
+ #include <algorithm>
23471
+ #include <iosfwd>
23472
+ #include <iterator>
23473
+ #include <string>
23474
+ #if __has_include(<string_view>) && __cplusplus >= 201703L
23475
+ #include <string_view>
23476
+ #endif
23477
+
23478
+ namespace duckdb_re2 {
23479
+
23480
+ class StringPiece {
23481
+ public:
23482
+ typedef std::char_traits<char> traits_type;
23483
+ typedef char value_type;
23484
+ typedef char* pointer;
23485
+ typedef const char* const_pointer;
23486
+ typedef char& reference;
23487
+ typedef const char& const_reference;
23488
+ typedef const char* const_iterator;
23489
+ typedef const_iterator iterator;
23490
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
23491
+ typedef const_reverse_iterator reverse_iterator;
23492
+ typedef size_t size_type;
23493
+ typedef ptrdiff_t difference_type;
23494
+ static const size_type npos = static_cast<size_type>(-1);
23495
+
23496
+ // We provide non-explicit singleton constructors so users can pass
23497
+ // in a "const char*" or a "string" wherever a "StringPiece" is
23498
+ // expected.
23499
+ StringPiece()
23500
+ : data_(NULL), size_(0) {}
23501
+ #if __has_include(<string_view>) && __cplusplus >= 201703L
23502
+ StringPiece(const std::string_view& str)
23503
+ : data_(str.data()), size_(str.size()) {}
23504
+ #endif
23505
+ StringPiece(const std::string& str)
23506
+ : data_(str.data()), size_(str.size()) {}
23507
+ StringPiece(const char* str)
23508
+ : data_(str), size_(str == NULL ? 0 : strlen(str)) {}
23509
+ StringPiece(const char* str, size_type len)
23510
+ : data_(str), size_(len) {}
23511
+
23512
+ const_iterator begin() const { return data_; }
23513
+ const_iterator end() const { return data_ + size_; }
23514
+ const_reverse_iterator rbegin() const {
23515
+ return const_reverse_iterator(data_ + size_);
23516
+ }
23517
+ const_reverse_iterator rend() const {
23518
+ return const_reverse_iterator(data_);
23519
+ }
23520
+
23521
+ size_type size() const { return size_; }
23522
+ size_type length() const { return size_; }
23523
+ bool empty() const { return size_ == 0; }
23524
+
23525
+ const_reference operator[](size_type i) const { return data_[i]; }
23526
+ const_pointer data() const { return data_; }
23527
+
23528
+ void remove_prefix(size_type n) {
23529
+ data_ += n;
23530
+ size_ -= n;
23531
+ }
23532
+
23533
+ void remove_suffix(size_type n) {
23534
+ size_ -= n;
23535
+ }
23536
+
23537
+ void set(const char* str) {
23538
+ data_ = str;
23539
+ size_ = str == NULL ? 0 : strlen(str);
23540
+ }
23541
+
23542
+ void set(const char* str, size_type len) {
23543
+ data_ = str;
23544
+ size_ = len;
23545
+ }
23546
+
23547
+ // Converts to `std::basic_string`.
23548
+ template <typename A>
23549
+ explicit operator std::basic_string<char, traits_type, A>() const {
23550
+ if (!data_) return {};
23551
+ return std::basic_string<char, traits_type, A>(data_, size_);
23552
+ }
23553
+
23554
+ std::string as_string() const {
23555
+ return std::string(data_, size_);
23556
+ }
23557
+
23558
+ // We also define ToString() here, since many other string-like
23559
+ // interfaces name the routine that converts to a C++ string
23560
+ // "ToString", and it's confusing to have the method that does that
23561
+ // for a StringPiece be called "as_string()". We also leave the
23562
+ // "as_string()" method defined here for existing code.
23563
+ std::string ToString() const {
23564
+ return std::string(data_, size_);
23565
+ }
23566
+
23567
+ void CopyToString(std::string* target) const {
23568
+ target->assign(data_, size_);
23569
+ }
23570
+
23571
+ void AppendToString(std::string* target) const {
23572
+ target->append(data_, size_);
23573
+ }
23574
+
23575
+ size_type copy(char* buf, size_type n, size_type pos = 0) const;
23576
+ StringPiece substr(size_type pos = 0, size_type n = npos) const;
23577
+
23578
+ int compare(const StringPiece& x) const {
23579
+ size_type min_size = std::min(size(), x.size());
23580
+ if (min_size > 0) {
23581
+ int r = memcmp(data(), x.data(), min_size);
23582
+ if (r < 0) return -1;
23583
+ if (r > 0) return 1;
23584
+ }
23585
+ if (size() < x.size()) return -1;
23586
+ if (size() > x.size()) return 1;
23587
+ return 0;
23588
+ }
23589
+
23590
+ // Does "this" start with "x"?
23591
+ bool starts_with(const StringPiece& x) const {
23592
+ return x.empty() ||
23593
+ (size() >= x.size() && memcmp(data(), x.data(), x.size()) == 0);
23594
+ }
23595
+
23596
+ // Does "this" end with "x"?
23597
+ bool ends_with(const StringPiece& x) const {
23598
+ return x.empty() ||
23599
+ (size() >= x.size() &&
23600
+ memcmp(data() + (size() - x.size()), x.data(), x.size()) == 0);
23601
+ }
23602
+
23603
+ bool contains(const StringPiece& s) const {
23604
+ return find(s) != npos;
23605
+ }
23606
+
23607
+ size_type find(const StringPiece& s, size_type pos = 0) const;
23608
+ size_type find(char c, size_type pos = 0) const;
23609
+ size_type rfind(const StringPiece& s, size_type pos = npos) const;
23610
+ size_type rfind(char c, size_type pos = npos) const;
23611
+
23612
+ private:
23613
+ const_pointer data_;
23614
+ size_type size_;
23615
+ };
23616
+
23617
+ inline bool operator==(const StringPiece& x, const StringPiece& y) {
23618
+ StringPiece::size_type len = x.size();
23619
+ if (len != y.size()) return false;
23620
+ return x.data() == y.data() || len == 0 ||
23621
+ memcmp(x.data(), y.data(), len) == 0;
23622
+ }
23623
+
23624
+ inline bool operator!=(const StringPiece& x, const StringPiece& y) {
23625
+ return !(x == y);
23626
+ }
23627
+
23628
+ inline bool operator<(const StringPiece& x, const StringPiece& y) {
23629
+ StringPiece::size_type min_size = std::min(x.size(), y.size());
23630
+ int r = min_size == 0 ? 0 : memcmp(x.data(), y.data(), min_size);
23631
+ return (r < 0) || (r == 0 && x.size() < y.size());
23632
+ }
23633
+
23634
+ inline bool operator>(const StringPiece& x, const StringPiece& y) {
23635
+ return y < x;
23636
+ }
23637
+
23638
+ inline bool operator<=(const StringPiece& x, const StringPiece& y) {
23639
+ return !(x > y);
23640
+ }
23641
+
23642
+ inline bool operator>=(const StringPiece& x, const StringPiece& y) {
23643
+ return !(x < y);
23644
+ }
23645
+
23646
+ // Allow StringPiece to be logged.
23647
+ std::ostream& operator<<(std::ostream& o, const StringPiece& p);
23648
+
23649
+ } // namespace duckdb_re2
23650
+
23651
+ #endif // RE2_STRINGPIECE_H_
23652
+
23653
+
23654
+ // LICENSE_CHANGE_END
23655
+
23656
+
23657
+ namespace duckdb_re2 {
23658
+ class Prog;
23659
+ class Regexp;
23660
+ } // namespace duckdb_re2
23661
+
23662
+ namespace duckdb_re2 {
23663
+
23664
+ // Interface for regular expression matching. Also corresponds to a
23665
+ // pre-compiled regular expression. An "RE2" object is safe for
23666
+ // concurrent use by multiple threads.
23667
+ class RE2 {
23668
+ public:
23669
+ // We convert user-passed pointers into special Arg objects
23670
+ class Arg;
23671
+ class Options;
23672
+
23673
+ // Defined in set.h.
23674
+ class Set;
23675
+
23676
+ enum ErrorCode {
23677
+ NoError = 0,
23678
+
23679
+ // Unexpected error
23680
+ ErrorInternal,
23681
+
23682
+ // Parse errors
23683
+ ErrorBadEscape, // bad escape sequence
23684
+ ErrorBadCharClass, // bad character class
23685
+ ErrorBadCharRange, // bad character class range
23686
+ ErrorMissingBracket, // missing closing ]
23687
+ ErrorMissingParen, // missing closing )
23688
+ ErrorTrailingBackslash, // trailing \ at end of regexp
23689
+ ErrorRepeatArgument, // repeat argument missing, e.g. "*"
23690
+ ErrorRepeatSize, // bad repetition argument
23691
+ ErrorRepeatOp, // bad repetition operator
23692
+ ErrorBadPerlOp, // bad perl operator
23693
+ ErrorBadUTF8, // invalid UTF-8 in regexp
23694
+ ErrorBadNamedCapture, // bad named capture group
23695
+ ErrorPatternTooLarge // pattern too large (compile failed)
23696
+ };
23697
+
23698
+ // Predefined common options.
23699
+ // If you need more complicated things, instantiate
23700
+ // an Option class, possibly passing one of these to
23701
+ // the Option constructor, change the settings, and pass that
23702
+ // Option class to the RE2 constructor.
23703
+ enum CannedOptions {
23704
+ DefaultOptions = 0,
23705
+ Latin1, // treat input as Latin-1 (default UTF-8)
23706
+ POSIX, // POSIX syntax, leftmost-longest match
23707
+ Quiet // do not log about regexp parse errors
23708
+ };
23709
+
23710
+ // Need to have the const char* and const std::string& forms for implicit
23711
+ // conversions when passing string literals to FullMatch and PartialMatch.
23712
+ // Otherwise the StringPiece form would be sufficient.
23713
+ #ifndef SWIG
23714
+ RE2(const char* pattern);
23715
+ RE2(const std::string& pattern);
23716
+ #endif
23717
+ RE2(const StringPiece& pattern);
23718
+ RE2(const StringPiece& pattern, const Options& options);
23719
+ ~RE2();
23720
+
23721
+ // Returns whether RE2 was created properly.
23722
+ bool ok() const { return error_code() == NoError; }
23723
+
23724
+ // The string specification for this RE2. E.g.
23725
+ // RE2 re("ab*c?d+");
23726
+ // re.pattern(); // "ab*c?d+"
23727
+ const std::string& pattern() const { return pattern_; }
23728
+
23729
+ // If RE2 could not be created properly, returns an error string.
23730
+ // Else returns the empty string.
23731
+ const std::string& error() const { return *error_; }
23732
+
23733
+ // If RE2 could not be created properly, returns an error code.
23734
+ // Else returns RE2::NoError (== 0).
23735
+ ErrorCode error_code() const { return error_code_; }
23736
+
23737
+ // If RE2 could not be created properly, returns the offending
23738
+ // portion of the regexp.
23739
+ const std::string& error_arg() const { return error_arg_; }
23740
+
23741
+ // Returns the program size, a very approximate measure of a regexp's "cost".
23742
+ // Larger numbers are more expensive than smaller numbers.
23743
+ int ProgramSize() const;
23744
+ int ReverseProgramSize() const;
23745
+
23746
+ // EXPERIMENTAL! SUBJECT TO CHANGE!
23747
+ // Outputs the program fanout as a histogram bucketed by powers of 2.
23748
+ // Returns the number of the largest non-empty bucket.
23749
+ int ProgramFanout(std::map<int, int>* histogram) const;
23750
+ int ReverseProgramFanout(std::map<int, int>* histogram) const;
23751
+
23752
+ // Returns the underlying Regexp; not for general use.
23753
+ // Returns entire_regexp_ so that callers don't need
23754
+ // to know about prefix_ and prefix_foldcase_.
23755
+ duckdb_re2::Regexp* Regexp() const { return entire_regexp_; }
23756
+
23757
+ /***** The array-based matching interface ******/
23758
+
23759
+ // The functions here have names ending in 'N' and are used to implement
23760
+ // the functions whose names are the prefix before the 'N'. It is sometimes
23761
+ // useful to invoke them directly, but the syntax is awkward, so the 'N'-less
23762
+ // versions should be preferred.
23763
+ static bool FullMatchN(const StringPiece& text, const RE2& re,
23764
+ const Arg* const args[], int n);
23765
+ static bool PartialMatchN(const StringPiece& text, const RE2& re,
23766
+ const Arg* const args[], int n);
23767
+ static bool ConsumeN(StringPiece* input, const RE2& re,
23768
+ const Arg* const args[], int n);
23769
+ static bool FindAndConsumeN(StringPiece* input, const RE2& re,
23770
+ const Arg* const args[], int n);
23771
+
23772
+ #ifndef SWIG
23773
+ private:
23774
+ template <typename F, typename SP>
23775
+ static inline bool Apply(F f, SP sp, const RE2& re) {
23776
+ return f(sp, re, NULL, 0);
23777
+ }
23778
+
23779
+ template <typename F, typename SP, typename... A>
23780
+ static inline bool Apply(F f, SP sp, const RE2& re, const A&... a) {
23781
+ const Arg* const args[] = {&a...};
23782
+ const int n = sizeof...(a);
23783
+ return f(sp, re, args, n);
23784
+ }
23785
+
23786
+ public:
23787
+ // In order to allow FullMatch() et al. to be called with a varying number
23788
+ // of arguments of varying types, we use two layers of variadic templates.
23789
+ // The first layer constructs the temporary Arg objects. The second layer
23790
+ // (above) constructs the array of pointers to the temporary Arg objects.
23791
+
23792
+ /***** The useful part: the matching interface *****/
23793
+
23794
+ // Matches "text" against "re". If pointer arguments are
23795
+ // supplied, copies matched sub-patterns into them.
23796
+ //
23797
+ // You can pass in a "const char*" or a "std::string" for "text".
23798
+ // You can pass in a "const char*" or a "std::string" or a "RE2" for "re".
23799
+ //
23800
+ // The provided pointer arguments can be pointers to any scalar numeric
23801
+ // type, or one of:
23802
+ // std::string (matched piece is copied to string)
23803
+ // StringPiece (StringPiece is mutated to point to matched piece)
23804
+ // T (where "bool T::ParseFrom(const char*, size_t)" exists)
23805
+ // (void*)NULL (the corresponding matched sub-pattern is not copied)
23806
+ //
23807
+ // Returns true iff all of the following conditions are satisfied:
23808
+ // a. "text" matches "re" exactly
23809
+ // b. The number of matched sub-patterns is >= number of supplied pointers
23810
+ // c. The "i"th argument has a suitable type for holding the
23811
+ // string captured as the "i"th sub-pattern. If you pass in
23812
+ // NULL for the "i"th argument, or pass fewer arguments than
23813
+ // number of sub-patterns, "i"th captured sub-pattern is
23814
+ // ignored.
23815
+ //
23816
+ // CAVEAT: An optional sub-pattern that does not exist in the
23817
+ // matched string is assigned the empty string. Therefore, the
23818
+ // following will return false (because the empty string is not a
23819
+ // valid number):
23820
+ // int number;
23821
+ // RE2::FullMatch("abc", "[a-z]+(\\d+)?", &number);
23822
+ template <typename... A>
23823
+ static bool FullMatch(const StringPiece& text, const RE2& re, A&&... a) {
23824
+ return Apply(FullMatchN, text, re, Arg(std::forward<A>(a))...);
23825
+ }
23826
+
23827
+ // Exactly like FullMatch(), except that "re" is allowed to match
23828
+ // a substring of "text".
23829
+ template <typename... A>
23830
+ static bool PartialMatch(const StringPiece& text, const RE2& re, A&&... a) {
23831
+ return Apply(PartialMatchN, text, re, Arg(std::forward<A>(a))...);
23832
+ }
23833
+
23834
+ // Like FullMatch() and PartialMatch(), except that "re" has to match
23835
+ // a prefix of the text, and "input" is advanced past the matched
23836
+ // text. Note: "input" is modified iff this routine returns true
23837
+ // and "re" matched a non-empty substring of "text".
23838
+ template <typename... A>
23839
+ static bool Consume(StringPiece* input, const RE2& re, A&&... a) {
23840
+ return Apply(ConsumeN, input, re, Arg(std::forward<A>(a))...);
23841
+ }
23842
+
23843
+ // Like Consume(), but does not anchor the match at the beginning of
23844
+ // the text. That is, "re" need not start its match at the beginning
23845
+ // of "input". For example, "FindAndConsume(s, "(\\w+)", &word)" finds
23846
+ // the next word in "s" and stores it in "word".
23847
+ template <typename... A>
23848
+ static bool FindAndConsume(StringPiece* input, const RE2& re, A&&... a) {
23849
+ return Apply(FindAndConsumeN, input, re, Arg(std::forward<A>(a))...);
23850
+ }
23851
+ #endif
23852
+
23853
+ // Replace the first match of "re" in "str" with "rewrite".
23854
+ // Within "rewrite", backslash-escaped digits (\1 to \9) can be
23855
+ // used to insert text matching corresponding parenthesized group
23856
+ // from the pattern. \0 in "rewrite" refers to the entire matching
23857
+ // text. E.g.,
23858
+ //
23859
+ // std::string s = "yabba dabba doo";
23860
+ // CHECK(RE2::Replace(&s, "b+", "d"));
23861
+ //
23862
+ // will leave "s" containing "yada dabba doo"
23863
+ //
23864
+ // Returns true if the pattern matches and a replacement occurs,
23865
+ // false otherwise.
23866
+ static bool Replace(std::string* str,
23867
+ const RE2& re,
23868
+ const StringPiece& rewrite);
23869
+
23870
+ // Like Replace(), except replaces successive non-overlapping occurrences
23871
+ // of the pattern in the string with the rewrite. E.g.
23872
+ //
23873
+ // std::string s = "yabba dabba doo";
23874
+ // CHECK(RE2::GlobalReplace(&s, "b+", "d"));
23875
+ //
23876
+ // will leave "s" containing "yada dada doo"
23877
+ // Replacements are not subject to re-matching.
23878
+ //
23879
+ // Because GlobalReplace only replaces non-overlapping matches,
23880
+ // replacing "ana" within "banana" makes only one replacement, not two.
23881
+ //
23882
+ // Returns the number of replacements made.
23883
+ static int GlobalReplace(std::string* str,
23884
+ const RE2& re,
23885
+ const StringPiece& rewrite);
23886
+
23887
+ // Like Replace, except that if the pattern matches, "rewrite"
23888
+ // is copied into "out" with substitutions. The non-matching
23889
+ // portions of "text" are ignored.
23890
+ //
23891
+ // Returns true iff a match occurred and the extraction happened
23892
+ // successfully; if no match occurs, the string is left unaffected.
23893
+ //
23894
+ // REQUIRES: "text" must not alias any part of "*out".
23895
+ static bool Extract(const StringPiece& text,
23896
+ const RE2& re,
23897
+ const StringPiece& rewrite,
23898
+ std::string* out);
23899
+
23900
+ // Escapes all potentially meaningful regexp characters in
23901
+ // 'unquoted'. The returned string, used as a regular expression,
23902
+ // will exactly match the original string. For example,
23903
+ // 1.5-2.0?
23904
+ // may become:
23905
+ // 1\.5\-2\.0\?
23906
+ static std::string QuoteMeta(const StringPiece& unquoted);
23907
+
23908
+ // Computes range for any strings matching regexp. The min and max can in
23909
+ // some cases be arbitrarily precise, so the caller gets to specify the
23910
+ // maximum desired length of string returned.
23911
+ //
23912
+ // Assuming PossibleMatchRange(&min, &max, N) returns successfully, any
23913
+ // string s that is an anchored match for this regexp satisfies
23914
+ // min <= s && s <= max.
23915
+ //
23916
+ // Note that PossibleMatchRange() will only consider the first copy of an
23917
+ // infinitely repeated element (i.e., any regexp element followed by a '*' or
23918
+ // '+' operator). Regexps with "{N}" constructions are not affected, as those
23919
+ // do not compile down to infinite repetitions.
23920
+ //
23921
+ // Returns true on success, false on error.
23922
+ bool PossibleMatchRange(std::string* min, std::string* max,
23923
+ int maxlen) const;
23924
+
23925
+ // Generic matching interface
23926
+
23927
+ // Type of match.
23928
+ enum Anchor {
23929
+ UNANCHORED, // No anchoring
23930
+ ANCHOR_START, // Anchor at start only
23931
+ ANCHOR_BOTH // Anchor at start and end
23932
+ };
23933
+
23934
+ // Return the number of capturing subpatterns, or -1 if the
23935
+ // regexp wasn't valid on construction. The overall match ($0)
23936
+ // does not count: if the regexp is "(a)(b)", returns 2.
23937
+ int NumberOfCapturingGroups() const { return num_captures_; }
23938
+
23939
+ // Return a map from names to capturing indices.
23940
+ // The map records the index of the leftmost group
23941
+ // with the given name.
23942
+ // Only valid until the re is deleted.
23943
+ const std::map<std::string, int>& NamedCapturingGroups() const;
23944
+
23945
+ // Return a map from capturing indices to names.
23946
+ // The map has no entries for unnamed groups.
23947
+ // Only valid until the re is deleted.
23948
+ const std::map<int, std::string>& CapturingGroupNames() const;
23949
+
23950
+ // General matching routine.
23951
+ // Match against text starting at offset startpos
23952
+ // and stopping the search at offset endpos.
23953
+ // Returns true if match found, false if not.
23954
+ // On a successful match, fills in submatch[] (up to nsubmatch entries)
23955
+ // with information about submatches.
23956
+ // I.e. matching RE2("(foo)|(bar)baz") on "barbazbla" will return true, with
23957
+ // submatch[0] = "barbaz", submatch[1].data() = NULL, submatch[2] = "bar",
23958
+ // submatch[3].data() = NULL, ..., up to submatch[nsubmatch-1].data() = NULL.
23959
+ // Caveat: submatch[] may be clobbered even on match failure.
23960
+ //
23961
+ // Don't ask for more match information than you will use:
23962
+ // runs much faster with nsubmatch == 1 than nsubmatch > 1, and
23963
+ // runs even faster if nsubmatch == 0.
23964
+ // Doesn't make sense to use nsubmatch > 1 + NumberOfCapturingGroups(),
23965
+ // but will be handled correctly.
23966
+ //
23967
+ // Passing text == StringPiece(NULL, 0) will be handled like any other
23968
+ // empty string, but note that on return, it will not be possible to tell
23969
+ // whether submatch i matched the empty string or did not match:
23970
+ // either way, submatch[i].data() == NULL.
23971
+ bool Match(const StringPiece& text,
23972
+ size_t startpos,
23973
+ size_t endpos,
23974
+ Anchor re_anchor,
23975
+ StringPiece* submatch,
23976
+ int nsubmatch) const;
23977
+
23978
+ // Check that the given rewrite string is suitable for use with this
23979
+ // regular expression. It checks that:
23980
+ // * The regular expression has enough parenthesized subexpressions
23981
+ // to satisfy all of the \N tokens in rewrite
23982
+ // * The rewrite string doesn't have any syntax errors. E.g.,
23983
+ // '\' followed by anything other than a digit or '\'.
23984
+ // A true return value guarantees that Replace() and Extract() won't
23985
+ // fail because of a bad rewrite string.
23986
+ bool CheckRewriteString(const StringPiece& rewrite,
23987
+ std::string* error) const;
23988
+
23989
+ // Returns the maximum submatch needed for the rewrite to be done by
23990
+ // Replace(). E.g. if rewrite == "foo \\2,\\1", returns 2.
23991
+ static int MaxSubmatch(const StringPiece& rewrite);
23992
+
23993
+ // Append the "rewrite" string, with backslash subsitutions from "vec",
23994
+ // to string "out".
23995
+ // Returns true on success. This method can fail because of a malformed
23996
+ // rewrite string. CheckRewriteString guarantees that the rewrite will
23997
+ // be sucessful.
23998
+ bool Rewrite(std::string* out,
23999
+ const StringPiece& rewrite,
24000
+ const StringPiece* vec,
24001
+ int veclen) const;
24002
+
24003
+ // Constructor options
24004
+ class Options {
24005
+ public:
24006
+ // The options are (defaults in parentheses):
24007
+ //
24008
+ // utf8 (true) text and pattern are UTF-8; otherwise Latin-1
24009
+ // posix_syntax (false) restrict regexps to POSIX egrep syntax
24010
+ // longest_match (false) search for longest match, not first match
24011
+ // log_errors (true) log syntax and execution errors to ERROR
24012
+ // max_mem (see below) approx. max memory footprint of RE2
24013
+ // literal (false) interpret string as literal, not regexp
24014
+ // never_nl (false) never match \n, even if it is in regexp
24015
+ // dot_nl (false) dot matches everything including new line
24016
+ // never_capture (false) parse all parens as non-capturing
24017
+ // case_sensitive (true) match is case-sensitive (regexp can override
24018
+ // with (?i) unless in posix_syntax mode)
24019
+ //
24020
+ // The following options are only consulted when posix_syntax == true.
24021
+ // When posix_syntax == false, these features are always enabled and
24022
+ // cannot be turned off; to perform multi-line matching in that case,
24023
+ // begin the regexp with (?m).
24024
+ // perl_classes (false) allow Perl's \d \s \w \D \S \W
24025
+ // word_boundary (false) allow Perl's \b \B (word boundary and not)
24026
+ // one_line (false) ^ and $ only match beginning and end of text
24027
+ //
24028
+ // The max_mem option controls how much memory can be used
24029
+ // to hold the compiled form of the regexp (the Prog) and
24030
+ // its cached DFA graphs. Code Search placed limits on the number
24031
+ // of Prog instructions and DFA states: 10,000 for both.
24032
+ // In RE2, those limits would translate to about 240 KB per Prog
24033
+ // and perhaps 2.5 MB per DFA (DFA state sizes vary by regexp; RE2 does a
24034
+ // better job of keeping them small than Code Search did).
24035
+ // Each RE2 has two Progs (one forward, one reverse), and each Prog
24036
+ // can have two DFAs (one first match, one longest match).
24037
+ // That makes 4 DFAs:
24038
+ //
24039
+ // forward, first-match - used for UNANCHORED or ANCHOR_START searches
24040
+ // if opt.longest_match() == false
24041
+ // forward, longest-match - used for all ANCHOR_BOTH searches,
24042
+ // and the other two kinds if
24043
+ // opt.longest_match() == true
24044
+ // reverse, first-match - never used
24045
+ // reverse, longest-match - used as second phase for unanchored searches
24046
+ //
24047
+ // The RE2 memory budget is statically divided between the two
24048
+ // Progs and then the DFAs: two thirds to the forward Prog
24049
+ // and one third to the reverse Prog. The forward Prog gives half
24050
+ // of what it has left over to each of its DFAs. The reverse Prog
24051
+ // gives it all to its longest-match DFA.
24052
+ //
24053
+ // Once a DFA fills its budget, it flushes its cache and starts over.
24054
+ // If this happens too often, RE2 falls back on the NFA implementation.
24055
+
24056
+ // For now, make the default budget something close to Code Search.
24057
+ static const int kDefaultMaxMem = 8<<20;
24058
+
24059
+ enum Encoding {
24060
+ EncodingUTF8 = 1,
24061
+ EncodingLatin1
24062
+ };
24063
+
24064
+ Options() :
24065
+ encoding_(EncodingUTF8),
24066
+ posix_syntax_(false),
24067
+ longest_match_(false),
24068
+ log_errors_(true),
24069
+ max_mem_(kDefaultMaxMem),
24070
+ literal_(false),
24071
+ never_nl_(false),
24072
+ dot_nl_(false),
24073
+ never_capture_(false),
24074
+ case_sensitive_(true),
24075
+ perl_classes_(false),
24076
+ word_boundary_(false),
24077
+ one_line_(false) {
24078
+ }
24079
+
24080
+ /*implicit*/ Options(CannedOptions);
24081
+
24082
+ Encoding encoding() const { return encoding_; }
24083
+ void set_encoding(Encoding encoding) { encoding_ = encoding; }
24084
+
24085
+ // Legacy interface to encoding.
24086
+ // TODO(rsc): Remove once clients have been converted.
24087
+ bool utf8() const { return encoding_ == EncodingUTF8; }
24088
+ void set_utf8(bool b) {
24089
+ if (b) {
24090
+ encoding_ = EncodingUTF8;
24091
+ } else {
24092
+ encoding_ = EncodingLatin1;
24093
+ }
24094
+ }
24095
+
24096
+ bool posix_syntax() const { return posix_syntax_; }
24097
+ void set_posix_syntax(bool b) { posix_syntax_ = b; }
24098
+
24099
+ bool longest_match() const { return longest_match_; }
24100
+ void set_longest_match(bool b) { longest_match_ = b; }
24101
+
24102
+ bool log_errors() const { return log_errors_; }
24103
+ void set_log_errors(bool b) { log_errors_ = b; }
24104
+
24105
+ int64_t max_mem() const { return max_mem_; }
24106
+ void set_max_mem(int64_t m) { max_mem_ = m; }
24107
+
24108
+ bool literal() const { return literal_; }
24109
+ void set_literal(bool b) { literal_ = b; }
24110
+
24111
+ bool never_nl() const { return never_nl_; }
24112
+ void set_never_nl(bool b) { never_nl_ = b; }
24113
+
24114
+ bool dot_nl() const { return dot_nl_; }
24115
+ void set_dot_nl(bool b) { dot_nl_ = b; }
24116
+
24117
+ bool never_capture() const { return never_capture_; }
24118
+ void set_never_capture(bool b) { never_capture_ = b; }
24119
+
24120
+ bool case_sensitive() const { return case_sensitive_; }
24121
+ void set_case_sensitive(bool b) { case_sensitive_ = b; }
24122
+
24123
+ bool perl_classes() const { return perl_classes_; }
24124
+ void set_perl_classes(bool b) { perl_classes_ = b; }
24125
+
24126
+ bool word_boundary() const { return word_boundary_; }
24127
+ void set_word_boundary(bool b) { word_boundary_ = b; }
24128
+
24129
+ bool one_line() const { return one_line_; }
24130
+ void set_one_line(bool b) { one_line_ = b; }
24131
+
24132
+ void Copy(const Options& src) {
24133
+ *this = src;
24134
+ }
24135
+
24136
+ int ParseFlags() const;
24137
+
24138
+ private:
24139
+ Encoding encoding_;
24140
+ bool posix_syntax_;
24141
+ bool longest_match_;
24142
+ bool log_errors_;
24143
+ int64_t max_mem_;
24144
+ bool literal_;
24145
+ bool never_nl_;
24146
+ bool dot_nl_;
24147
+ bool never_capture_;
24148
+ bool case_sensitive_;
24149
+ bool perl_classes_;
24150
+ bool word_boundary_;
24151
+ bool one_line_;
24152
+ };
24153
+
24154
+ // Returns the options set in the constructor.
24155
+ const Options& options() const { return options_; }
24156
+
24157
+ // Argument converters; see below.
24158
+ static inline Arg CRadix(short* x);
24159
+ static inline Arg CRadix(unsigned short* x);
24160
+ static inline Arg CRadix(int* x);
24161
+ static inline Arg CRadix(unsigned int* x);
24162
+ static inline Arg CRadix(long* x);
24163
+ static inline Arg CRadix(unsigned long* x);
24164
+ static inline Arg CRadix(long long* x);
24165
+ static inline Arg CRadix(unsigned long long* x);
24166
+
24167
+ static inline Arg Hex(short* x);
24168
+ static inline Arg Hex(unsigned short* x);
24169
+ static inline Arg Hex(int* x);
24170
+ static inline Arg Hex(unsigned int* x);
24171
+ static inline Arg Hex(long* x);
24172
+ static inline Arg Hex(unsigned long* x);
24173
+ static inline Arg Hex(long long* x);
24174
+ static inline Arg Hex(unsigned long long* x);
24175
+
24176
+ static inline Arg Octal(short* x);
24177
+ static inline Arg Octal(unsigned short* x);
24178
+ static inline Arg Octal(int* x);
24179
+ static inline Arg Octal(unsigned int* x);
24180
+ static inline Arg Octal(long* x);
24181
+ static inline Arg Octal(unsigned long* x);
24182
+ static inline Arg Octal(long long* x);
24183
+ static inline Arg Octal(unsigned long long* x);
24184
+
24185
+ private:
24186
+ void Init(const StringPiece& pattern, const Options& options);
24187
+
24188
+ bool DoMatch(const StringPiece& text,
24189
+ Anchor re_anchor,
24190
+ size_t* consumed,
24191
+ const Arg* const args[],
24192
+ int n) const;
24193
+
24194
+ duckdb_re2::Prog* ReverseProg() const;
24195
+
24196
+ std::string pattern_; // string regular expression
24197
+ Options options_; // option flags
24198
+ std::string prefix_; // required prefix (before regexp_)
24199
+ bool prefix_foldcase_; // prefix is ASCII case-insensitive
24200
+ duckdb_re2::Regexp* entire_regexp_; // parsed regular expression
24201
+ duckdb_re2::Regexp* suffix_regexp_; // parsed regular expression, prefix removed
24202
+ duckdb_re2::Prog* prog_; // compiled program for regexp
24203
+ int num_captures_; // Number of capturing groups
24204
+ bool is_one_pass_; // can use prog_->SearchOnePass?
24205
+
24206
+ mutable duckdb_re2::Prog* rprog_; // reverse program for regexp
24207
+ mutable const std::string* error_; // Error indicator
24208
+ // (or points to empty string)
24209
+ mutable ErrorCode error_code_; // Error code
24210
+ mutable std::string error_arg_; // Fragment of regexp showing error
24211
+
24212
+ // Map from capture names to indices
24213
+ mutable const std::map<std::string, int>* named_groups_;
24214
+
24215
+ // Map from capture indices to names
24216
+ mutable const std::map<int, std::string>* group_names_;
24217
+
24218
+ // Onces for lazy computations.
24219
+ mutable std::once_flag rprog_once_;
24220
+ mutable std::once_flag named_groups_once_;
24221
+ mutable std::once_flag group_names_once_;
24222
+
24223
+ RE2(const RE2&) = delete;
24224
+ RE2& operator=(const RE2&) = delete;
24225
+ };
24226
+
24227
+ /***** Implementation details *****/
24228
+
24229
+ // Hex/Octal/Binary?
24230
+
24231
+ // Special class for parsing into objects that define a ParseFrom() method
24232
+ template <class T>
24233
+ class _RE2_MatchObject {
24234
+ public:
24235
+ static inline bool Parse(const char* str, size_t n, void* dest) {
24236
+ if (dest == NULL) return true;
24237
+ T* object = reinterpret_cast<T*>(dest);
24238
+ return object->ParseFrom(str, n);
24239
+ }
24240
+ };
24241
+
24242
+ class RE2::Arg {
24243
+ public:
24244
+ // Empty constructor so we can declare arrays of RE2::Arg
24245
+ Arg();
24246
+
24247
+ // Constructor specially designed for NULL arguments
24248
+ Arg(void*);
24249
+ Arg(std::nullptr_t);
24250
+
24251
+ typedef bool (*Parser)(const char* str, size_t n, void* dest);
24252
+
24253
+ // Type-specific parsers
24254
+ #define MAKE_PARSER(type, name) \
24255
+ Arg(type* p) : arg_(p), parser_(name) {} \
24256
+ Arg(type* p, Parser parser) : arg_(p), parser_(parser) {}
24257
+
24258
+ MAKE_PARSER(char, parse_char)
24259
+ MAKE_PARSER(signed char, parse_schar)
24260
+ MAKE_PARSER(unsigned char, parse_uchar)
24261
+ MAKE_PARSER(float, parse_float)
24262
+ MAKE_PARSER(double, parse_double)
24263
+ MAKE_PARSER(std::string, parse_string)
24264
+ MAKE_PARSER(StringPiece, parse_stringpiece)
24265
+
24266
+ MAKE_PARSER(short, parse_short)
24267
+ MAKE_PARSER(unsigned short, parse_ushort)
24268
+ MAKE_PARSER(int, parse_int)
24269
+ MAKE_PARSER(unsigned int, parse_uint)
24270
+ MAKE_PARSER(long, parse_long)
24271
+ MAKE_PARSER(unsigned long, parse_ulong)
24272
+ MAKE_PARSER(long long, parse_longlong)
24273
+ MAKE_PARSER(unsigned long long, parse_ulonglong)
24274
+
24275
+ #undef MAKE_PARSER
24276
+
24277
+ // Generic constructor templates
24278
+ template <class T> Arg(T* p)
24279
+ : arg_(p), parser_(_RE2_MatchObject<T>::Parse) { }
24280
+ template <class T> Arg(T* p, Parser parser)
24281
+ : arg_(p), parser_(parser) { }
24282
+
24283
+ // Parse the data
24284
+ bool Parse(const char* str, size_t n) const;
24285
+
24286
+ private:
24287
+ void* arg_;
24288
+ Parser parser_;
24289
+
24290
+ static bool parse_null (const char* str, size_t n, void* dest);
24291
+ static bool parse_char (const char* str, size_t n, void* dest);
24292
+ static bool parse_schar (const char* str, size_t n, void* dest);
24293
+ static bool parse_uchar (const char* str, size_t n, void* dest);
24294
+ static bool parse_float (const char* str, size_t n, void* dest);
24295
+ static bool parse_double (const char* str, size_t n, void* dest);
24296
+ static bool parse_string (const char* str, size_t n, void* dest);
24297
+ static bool parse_stringpiece (const char* str, size_t n, void* dest);
24298
+
24299
+ #define DECLARE_INTEGER_PARSER(name) \
24300
+ private: \
24301
+ static bool parse_##name(const char* str, size_t n, void* dest); \
24302
+ static bool parse_##name##_radix(const char* str, size_t n, void* dest, \
24303
+ int radix); \
24304
+ \
24305
+ public: \
24306
+ static bool parse_##name##_hex(const char* str, size_t n, void* dest); \
24307
+ static bool parse_##name##_octal(const char* str, size_t n, void* dest); \
24308
+ static bool parse_##name##_cradix(const char* str, size_t n, void* dest);
24309
+
24310
+ DECLARE_INTEGER_PARSER(short)
24311
+ DECLARE_INTEGER_PARSER(ushort)
24312
+ DECLARE_INTEGER_PARSER(int)
24313
+ DECLARE_INTEGER_PARSER(uint)
24314
+ DECLARE_INTEGER_PARSER(long)
24315
+ DECLARE_INTEGER_PARSER(ulong)
24316
+ DECLARE_INTEGER_PARSER(longlong)
24317
+ DECLARE_INTEGER_PARSER(ulonglong)
24318
+
24319
+ #undef DECLARE_INTEGER_PARSER
24320
+
24321
+ };
24322
+
24323
+ inline RE2::Arg::Arg() : arg_(NULL), parser_(parse_null) { }
24324
+ inline RE2::Arg::Arg(void* p) : arg_(p), parser_(parse_null) { }
24325
+ inline RE2::Arg::Arg(std::nullptr_t p) : arg_(p), parser_(parse_null) { }
24326
+
24327
+ inline bool RE2::Arg::Parse(const char* str, size_t n) const {
24328
+ return (*parser_)(str, n, arg_);
24329
+ }
24330
+
24331
+ // This part of the parser, appropriate only for ints, deals with bases
24332
+ #define MAKE_INTEGER_PARSER(type, name) \
24333
+ inline RE2::Arg RE2::Hex(type* ptr) { \
24334
+ return RE2::Arg(ptr, RE2::Arg::parse_##name##_hex); \
24335
+ } \
24336
+ inline RE2::Arg RE2::Octal(type* ptr) { \
24337
+ return RE2::Arg(ptr, RE2::Arg::parse_##name##_octal); \
24338
+ } \
24339
+ inline RE2::Arg RE2::CRadix(type* ptr) { \
24340
+ return RE2::Arg(ptr, RE2::Arg::parse_##name##_cradix); \
24341
+ }
24342
+
24343
+ MAKE_INTEGER_PARSER(short, short)
24344
+ MAKE_INTEGER_PARSER(unsigned short, ushort)
24345
+ MAKE_INTEGER_PARSER(int, int)
24346
+ MAKE_INTEGER_PARSER(unsigned int, uint)
24347
+ MAKE_INTEGER_PARSER(long, long)
24348
+ MAKE_INTEGER_PARSER(unsigned long, ulong)
24349
+ MAKE_INTEGER_PARSER(long long, longlong)
24350
+ MAKE_INTEGER_PARSER(unsigned long long, ulonglong)
24351
+
24352
+ #undef MAKE_INTEGER_PARSER
24353
+
24354
+ #ifndef SWIG
24355
+
24356
+
24357
+ // Helper for writing global or static RE2s safely.
24358
+ // Write
24359
+ // static LazyRE2 re = {".*"};
24360
+ // and then use *re instead of writing
24361
+ // static RE2 re(".*");
24362
+ // The former is more careful about multithreaded
24363
+ // situations than the latter.
24364
+ //
24365
+ // N.B. This class never deletes the RE2 object that
24366
+ // it constructs: that's a feature, so that it can be used
24367
+ // for global and function static variables.
24368
+ class LazyRE2 {
24369
+ private:
24370
+ struct NoArg {};
24371
+
24372
+ public:
24373
+ typedef RE2 element_type; // support std::pointer_traits
24374
+
24375
+ // Constructor omitted to preserve braced initialization in C++98.
24376
+
24377
+ // Pretend to be a pointer to Type (never NULL due to on-demand creation):
24378
+ RE2& operator*() const { return *get(); }
24379
+ RE2* operator->() const { return get(); }
24380
+
24381
+ // Named accessor/initializer:
24382
+ RE2* get() const {
24383
+ std::call_once(once_, &LazyRE2::Init, this);
24384
+ return ptr_;
24385
+ }
24386
+
24387
+ // All data fields must be public to support {"foo"} initialization.
24388
+ const char* pattern_;
24389
+ RE2::CannedOptions options_;
24390
+ NoArg barrier_against_excess_initializers_;
24391
+
24392
+ mutable RE2* ptr_;
24393
+ mutable std::once_flag once_;
24394
+
24395
+ private:
24396
+ static void Init(const LazyRE2* lazy_re2) {
24397
+ lazy_re2->ptr_ = new RE2(lazy_re2->pattern_, lazy_re2->options_);
24398
+ }
24399
+
24400
+ void operator=(const LazyRE2&); // disallowed
24401
+ };
24402
+ #endif // SWIG
24403
+
24404
+ } // namespace duckdb_re2
24405
+
24406
+ using duckdb_re2::RE2;
24407
+ using duckdb_re2::LazyRE2;
24408
+
24409
+ #endif // RE2_RE2_H_
24410
+
24411
+
24412
+ // LICENSE_CHANGE_END
24413
+
24414
+
24415
+ namespace duckdb {
24416
+ // matches hive partitions in file name. For example:
24417
+ // - s3://bucket/var1=value1/bla/bla/var2=value2
24418
+ // - http(s)://domain(:port)/lala/kasdl/var1=value1/?not-a-var=not-a-value
24419
+ // - folder/folder/folder/../var1=value1/etc/.//var2=value2
24420
+ inline std::map<string, string> ParseHivePartitions(string filename) {
24421
+ std::map<string, string> result;
24422
+
24423
+ string regex = "[\\/\\\\]([^\\/\\?\\\\]+)=([^\\/\\n\\?\\\\]+)";
24424
+ duckdb_re2::StringPiece input(filename); // Wrap a StringPiece around it
24425
+
24426
+ string var;
24427
+ string value;
24428
+ while (RE2::FindAndConsume(&input, regex, &var, &value)) {
24429
+ result.insert(std::pair<string, string>(var, value));
24430
+ }
24431
+ return result;
24432
+ }
24433
+
23215
24434
  } // namespace duckdb
23216
24435
  //===----------------------------------------------------------------------===//
23217
24436
  // DuckDB