Skip to content

Commit

Permalink
Baljsn decoderoptionsutil drqs 175214394 (#4748)
Browse files Browse the repository at this point in the history
* drqs-175214394: 'baljsn_decoderoptionsutil': Initial.

* drqs-175214394: 'baljsn.txt': Update package doc.

* drqs-175214394: 'baljsn_decoderoptionsutil.h': Revisions per NGR 20240517.

* drqs-175214394: 'baljsn_decoderoptionsutil.h': Revisions per NGR 20240521.
  • Loading branch information
sbreitstein authored and GitHub Enterprise committed May 21, 2024
1 parent a309594 commit 309503e
Show file tree
Hide file tree
Showing 7 changed files with 463 additions and 5 deletions.
3 changes: 2 additions & 1 deletion groups/bal/baljsn/baljsn_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ BSLS_IDENT("$Id: $")
//@CLASSES:
// baljsn::Decoder: JSON decoder for 'bdeat'-compliant types
//
//@SEE_ALSO: baljsn_encoder, baljsn_parserutil, baljsn_parser
//@SEE_ALSO: baljsn_decoderoptions, balsjn_decoderoptionsutil,
// baljsn_encoder, baljsn_parserutil, baljsn_parser
//
//@DESCRIPTION: This component provides a class, 'baljsn::Decoder', for
// decoding value-semantic objects in the JSON format. In particular, the
Expand Down
6 changes: 3 additions & 3 deletions groups/bal/baljsn/baljsn_decoder.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ namespace test = BloombergLP::s_baltst;
// [13] FALLBACK ENUMERATORS
// [14] DECODING INTS AS ENUMS AND VICE VERSA {DRQS 166048981<GO>}
// [15] ARRAY HAVING NULLABLE COMPLEX ELEMENTS {DRQS 167908706<GO>}
// [17] 'DecoderOptions' CAN BE CONFIGURED FOR STRICT CONFORMANCE
// [18] USAGE EXAMPLE
// [16] 'DecoderOptions' CAN BE CONFIGURED FOR STRICT CONFORMANCE
// [17] USAGE EXAMPLE

// ============================================================================
// STANDARD BDE ASSERT TEST FUNCTION
Expand Down Expand Up @@ -36941,7 +36941,7 @@ int main(int argc, char *argv[])
cout << "TEST " << __FILE__ << " CASE " << test << endl;

switch (test) { case 0: // Zero is always the leading case.
case 18: {
case 17: {
// --------------------------------------------------------------------
// USAGE EXAMPLE
// Extracted from component header file.
Expand Down
56 changes: 56 additions & 0 deletions groups/bal/baljsn/baljsn_decoderoptionsutil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// baljsn_decoderoptionsutil.cpp -*-C++-*-
#include <baljsn_decoderoptionsutil.h>

#include <bsls_ident.h>
BSLS_IDENT_RCSID(baljsn_printutil_cpp,"$Id$ $CSID$")

#include <baljsn_decoderoptions.h>

#include <bsls_assert.h>

namespace BloombergLP {
namespace baljsn {

// ------------------------
// class DecoderOptionsUtil
// ------------------------

void DecoderOptionsUtil::setMode(DecoderOptions *options, Mode mode)
{

BSLS_ASSERT(options);

switch (mode) {
case e_DEFAULT: {
*options = DecoderOptions();
} break;
case e_STRICT_20240423: {
options->setValidateInputIsUtf8 (true );
options->setAllowConsecutiveSeparators (false);
options->setAllowFormFeedAsWhitespace (false);
options->setAllowUnescapedControlCharacters(false);
} break;
default: {
BSLS_ASSERT_OPT(!"reachable");
} break;
}
}

} // close package namespace
} // close enterprise namespace

// ----------------------------------------------------------------------------
// Copyright 2024 Bloomberg Finance L.P.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------- END-OF-FILE ----------------------------------
131 changes: 131 additions & 0 deletions groups/bal/baljsn/baljsn_decoderoptionsutil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// baljsn_decoderoptionsutil.h -*-C++-*-
#ifndef INCLUDED_BALJSN_DECODEROPTIONSUTIL
#define INCLUDED_BALJSN_DECODEROPTIONSUTIL

#include <bsls_ident.h>
BSLS_IDENT("$Id: $")

//@PURPOSE: Provide a utility for configuring 'baljsn::DecoderOptions'.
//
//@CLASSES:
// baljsn::DecoderOptionsUtil: utility for setting 'baljsn::DecoderOptions'
//
//@SEE_ALSO: baljsn_decoder, baljsn_decoderoptions
//
//@DESCRIPTION: This component provides a 'struct' of utility functions,
// 'baljsn::DecoderOptionsUtil', for configuring 'baljsn::DecoderOptions'
// object. In particular, this utility can be used to set the combination of
// options needed for strict compliance with the JSON grammar (see
// {'baljsn_decoder'|Strict Conformance}). This utility can also be used to
// set a 'baljsn::DecoderOptions' object to its default state.
//
///Modes
///-----
// When a default constructed 'baljsn::DecoderOptions' object is passed to the
// 'decode' methods of a 'baljsn::Decoder', several convenient variances from
// the JSON grammar are tolerated in the JSON document without causing failure.
// Specifically:
//..
// validateInputIsUtf8 false
// allowConsecutiveSeparators true
// allowFormFeedAsWhitespace true
// allowUnescapedControlCharacters true
//..
// See {'baljsn_decoderoptions'|Attributes} for examples. Should any of these
// variances be unacceptable, then one can flip individual options. Strict
// compliance (see 'bdljsn_jsontestsuiteutil') with the JSON grammar requires
// that each option named above be flipped to the opposite value:
//..
// validateInputIsUtf8 true
// allowConsecutiveSeparators false
// allowFormFeedAsWhitespace false
// allowUnescapedControlCharacters false
//..
// This utility defines the mode
// 'baljsn::DecoderOptionsUtil::e_STRICT_20240423' to allow all four options to
// be set with a single call.
//
// Note that 'baljsn::DecoderOptions' defines other options besides the four
// cited above. Those are *not* changed by setting the
// 'baljsn::DecoderOptionsUtil::e_STRICT_20240423' combination but are set when
// setting the options object using 'baljsn::DecoderOptionsUtil::e_DEFAULT'.
//
///Usage
///-----
// This section illustrates intended use of this component.
//
///Example 1: Setting 'baljsn::DecoderOptions' for Strictness
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Every call to one of the (non-deprecated) 'decode' functions of
// 'baljsn::Decoder' requires the user to provide a 'baljsn::DecoderOptions'
// object that allows the user to fine-tune the rules used when decoding the
// JSON document. The 'setMode' function of this utility provides a convenient
// way to set the option attributes to a combination that is deemed "strict"
// (i.e., strictly complying with the rules of the JSON grammar).
//
// First, create a 'baljsn::DecoderOptions' object:
//..
// baljsn::DecoderOptions options;
//..
// Now, set the option values for strict compliance:
//..
// baljsn::DecoderOptionsUtil::setMode(
// &options,
// baljsn::DecoderOptionsUtil::e_STRICT_20240423);
//..
// Finally, should there be a need, 'options' can be adjusted to a laxer set of
// rules by adjusting individual attributes or, if the original set of default
// attributes is needed, by using 'setMode':
//..
// baljsn::DecoderOptionsUtil::setMode(&options,
// baljsn::DecoderOptionsUtil::e_DEFAULT);
//..

#include <balscm_version.h>

namespace BloombergLP {
namespace baljsn {

class DecoderOptions;

// ========================
// class DecoderOptionsUtil
// ========================

struct DecoderOptionsUtil {
// This 'struct' provides a namespace for functions that set
// 'DecoderOptions' to particular configurations.

public:
// TYPES
enum Mode {
e_DEFAULT = 0 // set to default state
, e_STRICT_20240423 = 1 // set for strictness conformance per 2024-04-23
};

// CLASS METHODS
static void setMode(DecoderOptions *options, Mode mode);
// Set the attributes of the specified 'options' to the configuration
// associated with the specified 'mode'. See {Modes} for details.
};

} // close package namespace
} // close enterprise namespace

#endif

// ----------------------------------------------------------------------------
// Copyright 2024 Bloomberg Finance L.P.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------- END-OF-FILE ----------------------------------
Loading

0 comments on commit 309503e

Please sign in to comment.