$darkmode
#include <string.hpp>
Public Types | |
| using | Type = std::string |
Public Member Functions | |
| String (Type *ptr, std::string &&desc) | |
| String | not_empty () && |
| size_t | min_length () const |
| String | min_length (size_t value) && |
| void | set_min_length (size_t value) |
| size_t | max_length () const |
| String | max_length (size_t value) && |
| void | set_max_length (size_t value) |
| const std::string & | pattern () const |
| String | pattern (const std::string &value) && |
| void | set_pattern (const std::string &value) |
| String | c_identifier () && |
| bool | interpolate () const |
| String | interpolate (bool value) && |
| void | set_interpolate (bool value) |
| Environment * | environment () const |
| String | environment (Environment *env) && |
| void | set_environment (Environment *env) |
| const std::vector< std::string > & | enum_of () const |
| String | enum_of (std::vector< std::string > &&init) |
| void | set_enum_of (std::vector< std::string > &&init) |
| Json | json_schema () const override |
| void | validate (const Conf &c) const override |
| void | to_json (Json &j) const override |
| void | from_conf (const Conf &c) override |
| Json | serialize (const Type &x) const |
| Type | deserialize (const Conf &c) const |
| void | reset_ptr () override |
Public Member Functions inherited from fable::schema::Base< String > | |
| Base (JsonType t, std::string &&desc) | |
| Base (JsonType t) | |
| Base (std::string &&desc) | |
| Interface * | clone () const override |
| operator Box () const | |
| JsonType | type () const override |
| std::string | type_string () const override |
| Json | usage () const override |
| bool | is_required () const override |
| String | require () && |
| String | required (bool value) && |
| String | reset_pointer () && |
| bool | has_description () const |
| void | set_description (const std::string &s) override |
| void | set_description (std::string &&s) |
| const std::string & | description () const override |
| String | description (std::string &&desc) && |
Public Member Functions inherited from fable::schema::Interface | |
| virtual bool | is_variant () const |
| virtual bool | is_valid (const Conf &c) const |
| virtual Json | to_json () const |
Additional Inherited Members | |
Protected Member Functions inherited from fable::schema::Base< String > | |
| void | validate_type (const Conf &c) const |
| void | throw_error (const Conf &c, const char *format, Args... args) const |
| void | throw_error (const ConfError &e) const |
| void | throw_wrong_type (const Conf &c) const |
| void | augment_schema (Json &j) const |
Protected Attributes inherited from fable::schema::Base< String > | |
| JsonType | type_ |
| bool | required_ |
| std::string | desc_ |
String de-/serializes a string.
A string can have the following validation properties set:
The String schema type allows these properties to be specified and will validate them during deserialization.
| String fable::schema::String::c_identifier | ( | ) | && |
Ensure that the input matches an identifier as roughly specified by C.
This is shorthand for setting the pattern to FABLE_REGEX_C_IDENTIFIER.
| const std::vector< std::string > & fable::schema::String::enum_of | ( | ) | const |
Return the set of valid values for the string.
| String fable::schema::String::enum_of | ( | std::vector< std::string > && | init | ) |
Set the valid values for the string.
| init | list of valid values |
| Environment * fable::schema::String::environment | ( | ) | const |
Return the Environment used for variable interpolation.
| String fable::schema::String::environment | ( | Environment * | env | ) | && |
Set the Environment used for variable interpolation.
| environment |
|
overridevirtual |
Apply the input JSON configuration.
This does not validate the input.
Implements fable::schema::Interface.
| bool fable::schema::String::interpolate | ( | ) | const |
Return whether shell-style variable interpolation is enabled (default false).
| String fable::schema::String::interpolate | ( | bool | value | ) | && |
Set whether variable interpolation is enabled.
The following strings are then interpolated:
This uses the Environment set by the set_environment() method. If no environment is set, a default empty environment is used with OS environment fallback.
The string "${SHELL}" for example will evaluate to the current shell as defined in the OS environment, unless explicitely set in an Environment that is passed to set_environment().
Alternatives can be provided, such as with "${NOT_EXIST-alternate string}".
| value | true to enable |
|
overridevirtual |
Return the JSON schema.
Example output:
{ "$schema": "http://json-schema.org/draft-07/schema#", "description": "stand-in no-operation simulator", "properties": { "vehicles": { "description": "list of vehicle names to make available", "items": { "type": "string" }, "type": "array" } }, "title": "nop", "additionalProperties": false, "type": "object" }
See the following links for the specification:
Implements fable::schema::Interface.
| size_t fable::schema::String::max_length | ( | ) | const |
Return the current maximum length (max size_t value if unset).
| String fable::schema::String::max_length | ( | size_t | value | ) | && |
Set the maximum string length in bytes.
| value | max bytes |
| size_t fable::schema::String::min_length | ( | ) | const |
Return the current minimum length (0 if unset).
| String fable::schema::String::min_length | ( | size_t | value | ) | && |
Set the minimum string length in bytes.
| value | min bytes |
| String fable::schema::String::not_empty | ( | ) | && |
Ensure input is not empty if present.
This is effectively an alias for min_length(1).
| const std::string & fable::schema::String::pattern | ( | ) | const |
Return the regular expression pattern the string should match.
| String fable::schema::String::pattern | ( | const std::string & | value | ) | && |
Set the string regular expression pattern.
| value | regex pattern |
|
overridevirtual |
Reset the internal pointer to nullptr, protecting against invalid access.
This should be used when a schema is used after the backing data has been deleted.
Implements fable::schema::Interface.
| void fable::schema::String::set_enum_of | ( | std::vector< std::string > && | init | ) |
Set the valid values for the string.
| init | list of valid values |
| void fable::schema::String::set_environment | ( | Environment * | env | ) |
Set the Environment used for variable interpolation.
| environment |
| void fable::schema::String::set_interpolate | ( | bool | value | ) |
Set whether variable interpolation is enabled.
The following strings are then interpolated:
This uses the Environment set by the set_environment() method. If no environment is set, a default empty environment is used with OS environment fallback.
The string "${SHELL}" for example will evaluate to the current shell as defined in the OS environment, unless explicitely set in an Environment that is passed to set_environment().
Alternatives can be provided, such as with "${NOT_EXIST-alternate string}".
| value | true to enable |
| void fable::schema::String::set_max_length | ( | size_t | value | ) |
Set the maximum string length in bytes.
| value | maximum string length in bytes |
| void fable::schema::String::set_min_length | ( | size_t | value | ) |
Set the minimum string length in bytes.
| value | min bytes |
| void fable::schema::String::set_pattern | ( | const std::string & | value | ) |
Set the string regular expression pattern.
| value | regex pattern |
|
overridevirtual |
Return the current value of the destination.
Warning: This is NOT an efficient operation, but it can be useful for cases where speed is not important.
Implements fable::schema::Interface.
|
overridevirtual |
Validate the input JSON configuration.
If you don't have a Conf but would like to validate a Json type, then construct a Conf on the fly:
s.validate(Conf{j});
This function is not provided inline to prevent incorrect use.
Implements fable::schema::Interface.