blob: 25f5faa6a3ba501f6317378058892be81f5f728c (
plain)
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
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_NUMBER_PARSING_OPTIONS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_NUMBER_PARSING_OPTIONS_H_
#include "base/check_op.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace WTF {
// Copyable and immutable object representing number parsing flags.
class NumberParsingOptions {
STACK_ALLOCATED();
public:
static constexpr unsigned kNone = 0;
static constexpr unsigned kAcceptTrailingGarbage = 1;
static constexpr unsigned kAcceptLeadingPlus = 1 << 1;
static constexpr unsigned kAcceptLeadingTrailingWhitespace = 1 << 2;
static constexpr unsigned kAcceptMinusZeroForUnsigned = 1 << 3;
// 'Strict' behavior for WTF::String.
static constexpr unsigned kStrict =
kAcceptLeadingPlus | kAcceptLeadingTrailingWhitespace;
// Non-'Strict' behavior for WTF::String.
static constexpr unsigned kLoose = kStrict | kAcceptTrailingGarbage;
// This constructor allows implicit conversion from unsigned.
NumberParsingOptions(unsigned options) : options_(options) {
DCHECK_LT(options, 1u << 4) << "NumberParsingOptions should be built with "
"a combination of "
"NumberParsingOptions::kFoo constants.";
}
bool AcceptTrailingGarbage() const {
return options_ & kAcceptTrailingGarbage;
}
bool AcceptLeadingPlus() const { return options_ & kAcceptLeadingPlus; }
bool AcceptWhitespace() const {
return options_ & kAcceptLeadingTrailingWhitespace;
}
bool AcceptMinusZeroForUnsigned() const {
return options_ & kAcceptMinusZeroForUnsigned;
}
private:
unsigned options_;
};
} // namespace WTF
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_NUMBER_PARSING_OPTIONS_H_
|