Package ghidra.program.model.data

# Class StringRenderBuilder

java.lang.Object
ghidra.program.model.data.StringRenderBuilder

public class StringRenderBuilder extends Object
Helper class used to build up a formatted (for human consumption) string representation returned by Unicode and String data types.

Call `toString()` to retrieve the formatted string.

Example (quotes are part of result): `"Test\tstring",01,02,"Second\npart",00`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final char`
  `DOUBLE_QUOTE`
  `static final char`
  `SINGLE_QUOTE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StringRenderBuilder(int charSize)`
  `StringRenderBuilder(int charSize, char quoteChar)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addByteSeq(byte[] bytes)`
  Add byte values, shown as numeric hex values.
  `void`
  `addCodePointChar(int codePoint)`
  Add a single character.
  `void`
  `addCodePointValue(int codePoint)`
  Add a single character that needs to be shown as a numeric hex value.
  `void`
  `addEscapedChar(char ch)`
  Append the specified char after an escaping backslash "\", ie "x" -> "\x";
  `void`
  `addEscapedCodePoint(int codePoint)`
  Add an unicode codepoint as its escaped hex value, with a escape character prefix of 'x', 'u' or 'U' depending on the magnitude of the codePoint value.
  `void`
  `addString(String str)`
  Append the characters in the specified string.
  `boolean`
  `startsWithQuotedText()`
  Returns true if the current formatted string starts with a quoted text section, instead of a byte value section.
  `String`
  `toString()`
  Example (quotes are part of result): `"Test\tstring",01,02,"Second\npart",00`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### DOUBLE_QUOTE

    public static final char DOUBLE_QUOTE
    See Also:
      - Constant Field Values

  - ### SINGLE_QUOTE

    public static final char SINGLE_QUOTE
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### StringRenderBuilder

    public StringRenderBuilder(int charSize)

  - ### StringRenderBuilder

    public StringRenderBuilder(int charSize, char quoteChar)

- ## Method Details

  - ### startsWithQuotedText

    public boolean startsWithQuotedText()
    Returns true if the current formatted string starts with a quoted text section, instead of a byte value section. Useful to indicate if the string could have a prefix applied to it (ie. u8"text")

    Returns:
      boolean true if this string will start with a quoted text section

  - ### addString

    public void addString(String str)
    Append the characters in the specified string. The added characters will be shown in a quoted text region.
    Parameters:
      `str` - String to add

  - ### addEscapedChar

    public void addEscapedChar(char ch)
    Append the specified char after an escaping backslash "\", ie "x" -> "\x";
    Parameters:
      `ch` -

  - ### addCodePointChar

    public void addCodePointChar(int codePoint)
    Add a single character. It will be shown in a quoted text region.
    Parameters:
      `codePoint` - Character to add

  - ### addCodePointValue

    public void addCodePointValue(int codePoint)
    Add a single character that needs to be shown as a numeric hex value.
    Parameters:
      `codePoint` - Character to add

  - ### addByteSeq

    public void addByteSeq(byte[] bytes)
    Add byte values, shown as numeric hex values.

    { 0, 1, 2 } -> 00,01,02

    Parameters:
      `bytes` - to convert to hex and append. If null, append "???"

  - ### addEscapedCodePoint

    public void addEscapedCodePoint(int codePoint)
    Add an unicode codepoint as its escaped hex value, with a escape character prefix of 'x', 'u' or 'U' depending on the magnitude of the codePoint value.

    codePoint 15 -> '\' 'x' "0F"
    codePoint 65535 -> '\' 'u' "FFFF"
    codePoint 65536 -> '\' 'U' "10000"

    Parameters:
      `codePoint` - int value

  - ### toString

    public String toString()
    Example (quotes are part of result): `"Test\tstring",01,02,"Second\npart",00`

    Overrides:
      `toString` in class `Object`
    Returns:
      Formatted string