diff --git a/c/qrcodegen.c b/c/qrcodegen.c index de13309..1fd70ba 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -86,7 +86,8 @@ static int numCharCountBits(enum qrcodegen_Mode mode, int version); /*---- Private tables of constants ----*/ -// For checking text and encoding segments. +// The set of all legal characters in alphanumeric mode, where each character +// value maps to the index in the string. For checking text and encoding segments. static const char *ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; // For generating error correction codes. diff --git a/c/qrcodegen.h b/c/qrcodegen.h index 3215a6c..8ac9d3f 100644 --- a/c/qrcodegen.h +++ b/c/qrcodegen.h @@ -172,12 +172,15 @@ bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcod /* * Tests whether the given string can be encoded as a segment in alphanumeric mode. + * A string is encodable iff each character is in the following set: 0 to 9, A to Z + * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. */ bool qrcodegen_isAlphanumeric(const char *text); /* * Tests whether the given string can be encoded as a segment in numeric mode. + * A string is encodable iff each character is in the range 0 to 9. */ bool qrcodegen_isNumeric(const char *text); diff --git a/cpp/QrSegment.hpp b/cpp/QrSegment.hpp index 565778f..8e1356f 100644 --- a/cpp/QrSegment.hpp +++ b/cpp/QrSegment.hpp @@ -126,12 +126,15 @@ class QrSegment final { /* * Tests whether the given string can be encoded as a segment in alphanumeric mode. + * A string is encodable iff each character is in the following set: 0 to 9, A to Z + * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. */ public: static bool isAlphanumeric(const char *text); /* * Tests whether the given string can be encoded as a segment in numeric mode. + * A string is encodable iff each character is in the range 0 to 9. */ public: static bool isNumeric(const char *text); @@ -198,7 +201,8 @@ class QrSegment final { /*---- Private constant ----*/ - /* The set of all legal characters in alphanumeric mode, where each character value maps to the index in the string. */ + /* The set of all legal characters in alphanumeric mode, where + * each character value maps to the index in the string. */ private: static const char *ALPHANUMERIC_CHARSET; }; diff --git a/java/io/nayuki/qrcodegen/QrSegment.java b/java/io/nayuki/qrcodegen/QrSegment.java index 74dbc1b..da04109 100644 --- a/java/io/nayuki/qrcodegen/QrSegment.java +++ b/java/io/nayuki/qrcodegen/QrSegment.java @@ -222,13 +222,19 @@ public final class QrSegment { /*---- Constants ----*/ - /** Can test whether a string is encodable in numeric mode (such as by using {@link #makeNumeric(String)}). */ + /** Describes precisely all strings that are encodable in numeric mode. To test whether a + * string {@code s} is encodable: {@code boolean ok = NUMERIC_REGEX.matcher(s).matches();}. + * A string is encodable iff each character is in the range 0 to 9. */ public static final Pattern NUMERIC_REGEX = Pattern.compile("[0-9]*"); - /** Can test whether a string is encodable in alphanumeric mode (such as by using {@link #makeAlphanumeric(String)}). */ + /** Describes precisely all strings that are encodable in alphanumeric mode. To test whether a + * string {@code s} is encodable: {@code boolean ok = ALPHANUMERIC_REGEX.matcher(s).matches();}. + * A string is encodable iff each character is in the following set: 0 to 9, A to Z + * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. */ public static final Pattern ALPHANUMERIC_REGEX = Pattern.compile("[A-Z0-9 $%*+./:-]*"); - /** The set of all legal characters in alphanumeric mode, where each character value maps to the index in the string. */ + /** The set of all legal characters in alphanumeric mode, where + * each character value maps to the index in the string. */ static final String ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 7579698..e275cbd 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -834,13 +834,19 @@ var qrcodegen = new function() { var QrSegment = {}; // Private object to assign properties to. Not the same object as 'this.QrSegment'. - // (Public) Can test whether a string is encodable in numeric mode (such as by using QrSegment.makeNumeric()). + // (Public) Describes precisely all strings that are encodable in numeric mode. + // To test whether a string s is encodable: var ok = NUMERIC_REGEX.test(s); + // A string is encodable iff each character is in the range 0 to 9. this.QrSegment.NUMERIC_REGEX = /^[0-9]*$/; - // (Public) Can test whether a string is encodable in alphanumeric mode (such as by using QrSegment.makeAlphanumeric()). + // (Public) Describes precisely all strings that are encodable in alphanumeric mode. + // To test whether a string s is encodable: var ok = ALPHANUMERIC_REGEX.test(s); + // A string is encodable iff each character is in the following set: 0 to 9, A to Z + // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. this.QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/; - // (Private) The set of all legal characters in alphanumeric mode, where each character value maps to the index in the string. + // (Private) The set of all legal characters in alphanumeric mode, + // where each character value maps to the index in the string. QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 4a6c14c..55319cf 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -733,10 +733,16 @@ class QrSegment(object): # ---- Constants ---- - # (Public) Can test whether a string is encodable in numeric mode (such as by using make_numeric()) + # (Public) Describes precisely all strings that are encodable in numeric mode. + # To test whether a string s is encodable: ok = NUMERIC_REGEX.fullmatch(s) is not None + # A string is encodable iff each character is in the range 0 to 9. NUMERIC_REGEX = re.compile(r"[0-9]*\Z") - # (Public) Can test whether a string is encodable in alphanumeric mode (such as by using make_alphanumeric()) + # (Public) Describes precisely all strings that are encodable in alphanumeric mode. + # To test whether a string s is encodable: ok = ALPHANUMERIC_REGEX.fullmatch(s) is not None + # A string is encodable iff each character is in the following set: 0 to 9, A to Z + # (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. + ALPHANUMERIC_REGEX = re.compile(r"[A-Z0-9 $%*+./:-]*\Z") # (Private) Dictionary of "0"->0, "A"->10, "$"->37, etc. diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 8e3ea1e..de2fca8 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1002,12 +1002,15 @@ impl QrSegment { // Tests whether the given string can be encoded as a segment in alphanumeric mode. + // A string is encodable iff each character is in the following set: 0 to 9, A to Z + // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. fn is_alphanumeric(text: &[char]) -> bool { text.iter().all(|c| ALPHANUMERIC_CHARSET.contains(c)) } // Tests whether the given string can be encoded as a segment in numeric mode. + // A string is encodable iff each character is in the range 0 to 9. fn is_numeric(text: &[char]) -> bool { text.iter().all(|c| '0' <= *c && *c <= '9') } diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index aa31b85..49e0d7c 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -799,13 +799,19 @@ namespace qrcodegen { /*-- Constants --*/ - // Can test whether a string is encodable in numeric mode (such as by using QrSegment.makeNumeric()). + // Describes precisely all strings that are encodable in numeric mode. To test + // whether a string s is encodable: let ok: boolean = NUMERIC_REGEX.test(s); + // A string is encodable iff each character is in the range 0 to 9. public static readonly NUMERIC_REGEX: RegExp = /^[0-9]*$/; - // Can test whether a string is encodable in alphanumeric mode (such as by using QrSegment.makeAlphanumeric()). + // Describes precisely all strings that are encodable in alphanumeric mode. To test + // whether a string s is encodable: let ok: boolean = ALPHANUMERIC_REGEX.test(s); + // A string is encodable iff each character is in the following set: 0 to 9, A to Z + // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. public static readonly ALPHANUMERIC_REGEX: RegExp = /^[A-Z0-9 $%*+.\/:-]*$/; - // The set of all legal characters in alphanumeric mode, where each character value maps to the index in the string. + // The set of all legal characters in alphanumeric mode, + // where each character value maps to the index in the string. private static readonly ALPHANUMERIC_CHARSET: string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; }