Class QrSegmentAdvanced

java.lang.Object
io.nayuki.qrcodegen.QrSegmentAdvanced

public final class QrSegmentAdvanced
extends java.lang.Object
Splits text into optimal segments and encodes kanji segments. Provides static functions only; not instantiable.
See Also:
QrSegment, QrCode
  • Method Summary

    Modifier and Type Method Description
    static boolean isEncodableAsKanji​(java.lang.String text)
    Tests whether the specified string can be encoded as a segment in kanji mode.
    static QrSegment makeKanji​(java.lang.String text)
    Returns a segment representing the specified text string encoded in kanji mode.
    static java.util.List<QrSegment> makeSegmentsOptimally​(java.lang.String text, QrCode.Ecc ecl, int minVersion, int maxVersion)
    Returns a list of zero or more segments to represent the specified Unicode text string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • makeSegmentsOptimally

      public static java.util.List<QrSegment> makeSegmentsOptimally​(java.lang.String text, QrCode.Ecc ecl, int minVersion, int maxVersion)
      Returns a list of zero or more segments to represent the specified Unicode text string. The resulting list optimally minimizes the total encoded bit length, subjected to the constraints in the specified {error correction level, minimum version number, maximum version number}.

      This function can utilize all four text encoding modes: numeric, alphanumeric, byte (UTF-8), and kanji. This can be considered as a sophisticated but slower replacement for QrSegment.makeSegments(String). This requires more input parameters because it searches a range of versions, like QrCode.encodeSegments(List,QrCode.Ecc,int,int,int,boolean).

      Parameters:
      text - the text to be encoded (not null), which can be any Unicode string
      ecl - the error correction level to use (not null)
      minVersion - the minimum allowed version of the QR Code (at least 1)
      maxVersion - the maximum allowed version of the QR Code (at most 40)
      Returns:
      a new mutable list (not null) of segments (not null) containing the text, minimizing the bit length with respect to the constraints
      Throws:
      java.lang.NullPointerException - if the text or error correction level is null
      java.lang.IllegalArgumentException - if 1 ≤ minVersion ≤ maxVersion ≤ 40 is violated
      DataTooLongException - if the text fails to fit in the maxVersion QR Code at the ECL
    • makeKanji

      public static QrSegment makeKanji​(java.lang.String text)
      Returns a segment representing the specified text string encoded in kanji mode. Broadly speaking, the set of encodable characters are {kanji used in Japan, hiragana, katakana, East Asian punctuation, full-width ASCII, Greek, Cyrillic}. Examples of non-encodable characters include {ordinary ASCII, half-width katakana, more extensive Chinese hanzi}.
      Parameters:
      text - the text (not null), with only certain characters allowed
      Returns:
      a segment (not null) containing the text
      Throws:
      java.lang.NullPointerException - if the string is null
      java.lang.IllegalArgumentException - if the string contains non-encodable characters
      See Also:
      isEncodableAsKanji(String)
    • isEncodableAsKanji

      public static boolean isEncodableAsKanji​(java.lang.String text)
      Tests whether the specified string can be encoded as a segment in kanji mode. Broadly speaking, the set of encodable characters are {kanji used in Japan, hiragana, katakana, East Asian punctuation, full-width ASCII, Greek, Cyrillic}. Examples of non-encodable characters include {ordinary ASCII, half-width katakana, more extensive Chinese hanzi}.
      Parameters:
      text - the string to test for encodability (not null)
      Returns:
      true iff each character is in the kanji mode character set
      Throws:
      java.lang.NullPointerException - if the string is null
      See Also:
      makeKanji(String)