Exemple #1
0
        /// <summary>Initializes a new instance of the
        /// <see cref='PeterO.Cbor2.PODOptions'/> class.</summary>
        /// <param name='paramString'>A string setting forth the options to
        /// use. This is a semicolon-separated list of options, each of which
        /// has a key and a value separated by an equal sign ("="). Whitespace
        /// and line separators are not allowed to appear between the
        /// semicolons or between the equal signs, nor may the string begin or
        /// end with whitespace. The string can be empty, but cannot be null.
        /// The following is an example of this parameter:
        /// <c>usecamelcase=true</c>. The key can be any one of the following
        /// where the letters can be any combination of basic upper-case and/or
        /// basic lower-case letters: <c>usecamelcase</c>. Other keys are
        /// ignored in this version of the CBOR library. (Keys are compared
        /// using a basic case-insensitive comparison, in which two strings are
        /// equal if they match after converting the basic upper-case letters A
        /// to Z (U+0041 to U+005A) in both strings to basic lower-case
        /// letters.) If two or more key/value pairs have equal keys (in a
        /// basic case-insensitive comparison), the value given for the last
        /// such key is used. The key just given can have a value of <c>1</c>,
        /// <c>true</c>, <c>yes</c>, or <c>on</c> (where the letters can be
        /// any combination of basic upper-case and/or basic lower-case
        /// letters), which means true, and any other value meaning false. For
        /// example, <c>usecamelcase=Yes</c> and <c>usecamelcase=1</c> both set
        /// the <c>UseCamelCase</c> property to true. In the future, this class
        /// may allow other keys to store other kinds of values, not just true
        /// or false.</param>
        /// <exception cref='ArgumentNullException'>The parameter <paramref
        /// name='paramString'/> is null.</exception>
        public PODOptions(string paramString)
        {
            if (paramString == null)
            {
                throw new ArgumentNullException(nameof(paramString));
            }
            var parser = new OptionsParser(paramString);

            this.UseCamelCase = parser.GetBoolean("usecamelcase", true);
        }
        /// <summary>Initializes a new instance of the
        /// <see cref='PeterO.Cbor2.CBOREncodeOptions'/> class.</summary>
        /// <param name='paramString'>A string setting forth the options to
        /// use. This is a semicolon-separated list of options, each of which
        /// has a key and a value separated by an equal sign ("="). Whitespace
        /// and line separators are not allowed to appear between the
        /// semicolons or between the equal signs, nor may the string begin or
        /// end with whitespace. The string can be empty, but cannot be null.
        /// The following is an example of this parameter:
        /// <c>allowduplicatekeys=true;ctap2Canonical=true</c>. The key can be
        /// any one of the following where the letters can be any combination
        /// of basic upper-case and/or basic lower-case letters:
        /// <c>allowduplicatekeys</c>, <c>ctap2canonical</c>,
        /// <c>resolvereferences</c>, <c>useindeflengthstrings</c>,
        /// <c>allowempty</c>, <c>float64</c>. Keys other than these are
        /// ignored in this version of the CBOR library. The key <c>float64</c>
        /// was introduced in version 4.4 of this library. (Keys are compared
        /// using a basic case-insensitive comparison, in which two strings are
        /// equal if they match after converting the basic upper-case letters A
        /// to Z (U+0041 to U+005A) in both strings to basic lower-case
        /// letters.) If two or more key/value pairs have equal keys (in a
        /// basic case-insensitive comparison), the value given for the last
        /// such key is used. The four keys just given can have a value of
        /// <c>1</c>, <c>true</c>, <c>yes</c>, or <c>on</c> (where the
        /// letters can be any combination of basic upper-case and/or basic
        /// lower-case letters), which means true, and any other value meaning
        /// false. For example, <c>allowduplicatekeys=Yes</c> and
        /// <c>allowduplicatekeys=1</c> both set the <c>AllowDuplicateKeys</c>
        /// property to true. In the future, this class may allow other keys to
        /// store other kinds of values, not just true or false.</param>
        /// <exception cref='ArgumentNullException'>The parameter <paramref
        /// name='paramString'/> is null.</exception>
        public CBOREncodeOptions(string paramString)
        {
            if (paramString == null)
            {
                throw new ArgumentNullException(nameof(paramString));
            }
            var parser = new OptionsParser(paramString);

            this.ResolveReferences = parser.GetBoolean("resolvereferences",
                                                       false);
            this.UseIndefLengthStrings = parser.GetBoolean(
                "useindeflengthstrings",
                false);
            this.Float64 = parser.GetBoolean(
                "float64",
                false);
            this.AllowDuplicateKeys = parser.GetBoolean("allowduplicatekeys",
                                                        false);
            this.AllowEmpty     = parser.GetBoolean("allowempty", false);
            this.Ctap2Canonical = parser.GetBoolean("ctap2canonical", false);
        }
Exemple #3
0
        /// <summary>Initializes a new instance of the
        /// <see cref='PeterO.Cbor2.JSONOptions'/> class.</summary>
        /// <param name='paramString'>A string setting forth the options to
        /// use. This is a semicolon-separated list of options, each of which
        /// has a key and a value separated by an equal sign ("="). Whitespace
        /// and line separators are not allowed to appear between the
        /// semicolons or between the equal signs, nor may the string begin or
        /// end with whitespace. The string can be empty, but cannot be null.
        /// The following is an example of this parameter:
        /// <c>base64padding=false;replacesurrogates=true</c>. The key can be
        /// any one of the following where the letters can be any combination
        /// of basic upper-case and/or basic lower-case letters:
        /// <c>base64padding</c>, <c>replacesurrogates</c>,
        /// <c>allowduplicatekeys</c>, <c>preservenegativezero</c>,
        /// <c>numberconversion</c>. Other keys are ignored in this version of
        /// the CBOR library. (Keys are compared using a basic case-insensitive
        /// comparison, in which two strings are equal if they match after
        /// converting the basic upper-case letters A to Z (U+0041 to U+005A)
        /// in both strings to basic lower-case letters.) If two or more
        /// key/value pairs have equal keys (in a basic case-insensitive
        /// comparison), the value given for the last such key is used. The
        /// first four keys just given can have a value of <c>1</c>,
        /// <c>true</c>, <c>yes</c>, or <c>on</c> (where the letters can be
        /// any combination of basic upper-case and/or basic lower-case
        /// letters), which means true, and any other value meaning false. The
        /// last key, <c>numberconversion</c>, can have a value of any name
        /// given in the <c>JSONOptions.ConversionMode</c> enumeration (where
        /// the letters can be any combination of basic upper-case and/or basic
        /// lower-case letters), and any other value is unrecognized. (If the
        /// <c>numberconversion</c> key is not given, its value is treated as
        /// <c>full</c>. If that key is given, but has an unrecognized value,
        /// an exception is thrown.) For example, <c>base64padding=Yes</c> and
        /// <c>base64padding=1</c> both set the <c>Base64Padding</c> property
        /// to true, and <c>numberconversion=double</c> sets the
        /// <c>NumberConversion</c> property to <c>ConversionMode.Double</c>
        /// .</param>
        /// <exception cref='ArgumentNullException'>The parameter <paramref
        /// name='paramString'/> is null. In the future, this class may allow
        /// other keys to store other kinds of values, not just true or
        /// false.</exception>
        /// <exception cref='ArgumentException'>An unrecognized value for
        /// <c>numberconversion</c> was given.</exception>
        public JSONOptions(string paramString)
        {
            if (paramString == null)
            {
                throw new ArgumentNullException(nameof(paramString));
            }
            var parser = new OptionsParser(paramString);

            this.PreserveNegativeZero = parser.GetBoolean(
                "preservenegativezero",
                true);
            this.AllowDuplicateKeys = parser.GetBoolean(
                "allowduplicatekeys",
                false);
            this.Base64Padding     = parser.GetBoolean("base64padding", true);
            this.ReplaceSurrogates = parser.GetBoolean(
                "replacesurrogates",
                false);
            this.NumberConversion = ToNumberConversion(parser.GetLCString(
                                                           "numberconversion",
                                                           null));
        }