Generate code for a naxp
If you want to implement a specific naxp but
- you don’t want to link in a library,
- you don’t want to pay the run-time cost associated with a library for something that can be completely determined in advance, or
- there is no library for your language,
then code generation may be the answer, which is what this page is for.
Tip If you are …
- … designing a naxp then first use the interactive design page to make sure your naxp works as expected.
- … migrating a naxp from one version to another then first use the migration tester to ensure stored encoded values continue to mean the same thing.
- … using C#, then the source generator in the NuGet package gets you the same code as this page but generated automatically from your source code.
The code generator below produces a single self-contained code fragment without namespace, class, header or using directives that can be dropped directly into your code. If you need more than one naxp in the same place then use the ‘Name prefix’ text box to add a prefix to all functions and constants to disambiguate them.
The generated code API is similar to the corresponding library API for a single naxp and is fully documented. The following is a high level summary (with precise naming following the language’s convention):
accepts(...)tests whether text is valid.encode(...)gets the encoded value of text (with0indicating invalid text).decode(...)and friends get the (canonical) text from an encoded value.getCanonicalForm(...)and friends get the canonical form of text.patternis the original naxp pattern used to generate the code.maxEncodedValueis the largest possible encoded value.-
maxLengthis the length of the longest canonical text – a buffer this size is sufficient for any text returned bydecodeorgetCanonicalForm.
The code generator