Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 4.23 KB

validate_encodable_as.rst

File metadata and controls

67 lines (49 loc) · 4.23 KB

validate_encodable_as

ztd::text::validate_encodable_as is a function that takes an input sequence of code_points and attempts to validate that they can be turned into the code_units of the provided encoding. Unlike the ztd::text::count_as_encoded </api/conversions/validate_encodable_as> function, this does not take an error handler. Any error, even if it would be corrected over, produces a stop in the algorithm and a validate_result </api/validate_result>/stateless_validate_result </api/stateless_validate_result> object gets returned with the .valid member set to false.

The overloads of this function increase the level of control with each passed argument. At the last overload with four arguments, the function attempts to work call some extension points or falls back to the base function call in this order:

  • The text_validate_encodable_as(input, encoding, encode_state) extension point, if possible.
  • The text_validate_encodable_as(input, encoding, encode_state, decode_state) extension point, if possible.
  • An internal, implementation-defined customization point.
  • The basic_validate_encodable_as base function.

The base function call, basic_validate_encodable_as, simply performs the core validating loop </design/converting/validate decodable> using the Lucky 7 </design/lucky 7> design. The reason the last overload takes 2 state arguments is due to how the base implementation works from the core validating loop. If during the 3-argument overload it is detected that text_validate_encodable_as(input, encoding, encode_state) can be called, it will be called without attempt to create an decode_state value with ztd::text::make_decode_state(...) </api/make_decode_state>.

During the basic_validate_encodable_as loop, if it detects that there is a preferable text_validate_decodable_as_one, it will call that method as text_validate_encodable_as_one(input, encoding, encode_state) inside of the loop rather than doing the core design.

The ztd::text::validate_result </api/validate_result> type only includes the encode_state in all cases.

Note

👉 This means that if you implement none of the extension points whatsoever, implementing the basic decode_one and encode_one functions on your Encoding Object type will guarantee a proper, working implementation.

Note

👉 If you need to call the "basic" form of this function that takes no secret implementation shortcuts or user-defined extension points, then call basic_validate_encodable_as directly. This can be useful to stop infinity loops when your extension points cannot handle certain inputs and thereby needs to "delegate" to the basic case.


Functions

ztd_text_validate_encodable_as