BDE 4.14.0 Production release
Loading...
Searching...
No Matches
baljsn_decoderoptionsutil.h
Go to the documentation of this file.
1/// @file baljsn_decoderoptionsutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// baljsn_decoderoptionsutil.h -*-C++-*-
8#ifndef INCLUDED_BALJSN_DECODEROPTIONSUTIL
9#define INCLUDED_BALJSN_DECODEROPTIONSUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup baljsn_decoderoptionsutil baljsn_decoderoptionsutil
15/// @brief Provide a utility for configuring `baljsn::DecoderOptions`.
16/// @addtogroup bal
17/// @{
18/// @addtogroup baljsn
19/// @{
20/// @addtogroup baljsn_decoderoptionsutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#baljsn_decoderoptionsutil-purpose"> Purpose</a>
25/// * <a href="#baljsn_decoderoptionsutil-classes"> Classes </a>
26/// * <a href="#baljsn_decoderoptionsutil-description"> Description </a>
27/// * <a href="#baljsn_decoderoptionsutil-modes"> Modes </a>
28/// * <a href="#baljsn_decoderoptionsutil-usage"> Usage </a>
29/// * <a href="#baljsn_decoderoptionsutil-example-1-setting-baljsn-decoderoptions-for-strictness"> Example 1: Setting baljsn::DecoderOptions for Strictness </a>
30///
31/// # Purpose {#baljsn_decoderoptionsutil-purpose}
32/// Provide a utility for configuring `baljsn::DecoderOptions`.
33///
34/// # Classes {#baljsn_decoderoptionsutil-classes}
35///
36/// - baljsn::DecoderOptionsUtil: utility for setting `baljsn::DecoderOptions`
37///
38/// @see baljsn_decoder, baljsn_decoderoptions
39///
40/// # Description {#baljsn_decoderoptionsutil-description}
41/// This component provides a `struct` of utility functions,
42/// `baljsn::DecoderOptionsUtil`, for configuring `baljsn::DecoderOptions`
43/// object. In particular, this utility can be used to set the combination of
44/// options needed for strict compliance with the JSON grammar (see
45/// @ref baljsn_decoder-strict-conformance . This utility can also be used to
46/// set a `baljsn::DecoderOptions` object to its default state.
47///
48/// ## Modes {#baljsn_decoderoptionsutil-modes}
49///
50///
51/// When a default constructed `baljsn::DecoderOptions` object is passed to the
52/// `decode` methods of a `baljsn::Decoder`, several convenient variances from
53/// the JSON grammar are tolerated in the JSON document without causing failure.
54/// Specifically:
55/// @code
56/// validateInputIsUtf8 false
57/// allowConsecutiveSeparators true
58/// allowFormFeedAsWhitespace true
59/// allowUnescapedControlCharacters true
60/// @endcode
61/// See @ref baljsn_decoderoptions-attributes for examples. Should any of these
62/// variances be unacceptable, then one can flip individual options. Strict
63/// compliance (see @ref bdljsn_jsontestsuiteutil ) with the JSON grammar requires
64/// that each option named above be flipped to the opposite value:
65/// @code
66/// validateInputIsUtf8 true
67/// allowConsecutiveSeparators false
68/// allowFormFeedAsWhitespace false
69/// allowUnescapedControlCharacters false
70/// @endcode
71/// This utility defines the mode
72/// `baljsn::DecoderOptionsUtil::e_STRICT_20240423` to allow all four options to
73/// be set with a single call.
74///
75/// Note that `baljsn::DecoderOptions` defines other options besides the four
76/// cited above. Those are *not* changed by setting the
77/// `baljsn::DecoderOptionsUtil::e_STRICT_20240423` combination but are set when
78/// setting the options object using `baljsn::DecoderOptionsUtil::e_DEFAULT`.
79///
80/// ## Usage {#baljsn_decoderoptionsutil-usage}
81///
82///
83/// This section illustrates intended use of this component.
84///
85/// ### Example 1: Setting baljsn::DecoderOptions for Strictness {#baljsn_decoderoptionsutil-example-1-setting-baljsn-decoderoptions-for-strictness}
86///
87///
88/// Every call to one of the (non-deprecated) `decode` functions of
89/// `baljsn::Decoder` requires the user to provide a `baljsn::DecoderOptions`
90/// object that allows the user to fine-tune the rules used when decoding the
91/// JSON document. The `setMode` function of this utility provides a convenient
92/// way to set the option attributes to a combination that is deemed "strict"
93/// (i.e., strictly complying with the rules of the JSON grammar).
94///
95/// First, create a `baljsn::DecoderOptions` object:
96/// @code
97/// baljsn::DecoderOptions options;
98/// @endcode
99/// Now, set the option values for strict compliance:
100/// @code
101/// baljsn::DecoderOptionsUtil::setMode(
102/// &options,
103/// baljsn::DecoderOptionsUtil::e_STRICT_20240423);
104/// @endcode
105/// Finally, should there be a need, `options` can be adjusted to a laxer set of
106/// rules by adjusting individual attributes or, if the original set of default
107/// attributes is needed, by using `setMode`:
108/// @code
109/// baljsn::DecoderOptionsUtil::setMode(&options,
110/// baljsn::DecoderOptionsUtil::e_DEFAULT);
111/// @endcode
112/// @}
113/** @} */
114/** @} */
115
116/** @addtogroup bal
117 * @{
118 */
119/** @addtogroup baljsn
120 * @{
121 */
122/** @addtogroup baljsn_decoderoptionsutil
123 * @{
124 */
125
126#include <balscm_version.h>
127
128
129namespace baljsn {
130
131class DecoderOptions;
132
133 // ========================
134 // class DecoderOptionsUtil
135 // ========================
136
137/// This `struct` provides a namespace for functions that set
138/// `DecoderOptions` to particular configurations.
140
141 public:
142 // TYPES
143 enum Mode {
144 e_DEFAULT = 0 // set to default state
145 , e_STRICT_20240423 = 1 // set for strictness conformance per 2024-04-23
146 };
147
148 // CLASS METHODS
149
150 /// Set the attributes of the specified `options` to the configuration
151 /// associated with the specified `mode`. See {Modes} for details.
152 static void setMode(DecoderOptions *options, Mode mode);
153};
154
155} // close package namespace
156
157
158#endif
159
160// ----------------------------------------------------------------------------
161// Copyright 2024 Bloomberg Finance L.P.
162//
163// Licensed under the Apache License, Version 2.0 (the "License");
164// you may not use this file except in compliance with the License.
165// You may obtain a copy of the License at
166//
167// http://www.apache.org/licenses/LICENSE-2.0
168//
169// Unless required by applicable law or agreed to in writing, software
170// distributed under the License is distributed on an "AS IS" BASIS,
171// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
172// See the License for the specific language governing permissions and
173// limitations under the License.
174// ----------------------------- END-OF-FILE ----------------------------------
175
176/** @} */
177/** @} */
178/** @} */
Definition baljsn_decoderoptions.h:153
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition baljsn_datumdecoderoptions.h:113
Definition baljsn_decoderoptionsutil.h:139
Mode
Definition baljsn_decoderoptionsutil.h:143
@ e_STRICT_20240423
Definition baljsn_decoderoptionsutil.h:145
@ e_DEFAULT
Definition baljsn_decoderoptionsutil.h:144
static void setMode(DecoderOptions *options, Mode mode)