Class StructuredTextImpl

java.lang.Object
org.eclipse.equinox.bidi.internal.StructuredTextImpl
All Implemented Interfaces:
IStructuredTextExpert

public class StructuredTextImpl extends Object implements IStructuredTextExpert
Implementation for IStructuredTextExpert.
  • Field Details

  • Constructor Details

    • StructuredTextImpl

      public StructuredTextImpl(StructuredTextTypeHandler structuredTextHandler, StructuredTextEnvironment environment, boolean shared)
      Constructor used in StructuredTextExpertFactory.
      Parameters:
      structuredTextHandler - the structured text handler used by this expert.
      environment - the environment associated with this expert.
      shared - flag which is true if the expert is stateful.
  • Method Details

    • getTypeHandler

      public StructuredTextTypeHandler getTypeHandler()
      Description copied from interface: IStructuredTextExpert
      Obtains the structured type handler associated with this IStructuredTextExpert instance.
      Specified by:
      getTypeHandler in interface IStructuredTextExpert
      Returns:
      the type handler instance.
    • getEnvironment

      public StructuredTextEnvironment getEnvironment()
      Description copied from interface: IStructuredTextExpert
      Obtains the environment associated with this IStructuredTextExpert instance.
      Specified by:
      getEnvironment in interface IStructuredTextExpert
      Returns:
      the environment instance.
    • getTextDirection

      public int getTextDirection(String text)
      Description copied from interface: IStructuredTextExpert
      Get the base direction of a structured text. This base direction may depend on whether the text contains Arabic or Hebrew words. If the text contains both, the first Arabic or Hebrew letter in the text determines which is the governing script.
      Specified by:
      getTextDirection in interface IStructuredTextExpert
      Parameters:
      text - is the structured text string.
      Returns:
      the base direction of the structured text, IStructuredTextExpert.DIR_LTR or IStructuredTextExpert.DIR_RTL
    • clearState

      public void clearState()
      Description copied from interface: IStructuredTextExpert
      Resets the state to initial. This method does nothing if the expert instance is not a stateful one.
      Specified by:
      clearState in interface IStructuredTextExpert
    • setState

      public void setState(Object newState)
      Description copied from interface: IStructuredTextExpert
      Sets the state for the next text processing call. This method does nothing if the expert instance is not a stateful one.
      Specified by:
      setState in interface IStructuredTextExpert
      Parameters:
      newState - an object returned by a previous call to IStructuredTextExpert.getState().
    • getState

      public Object getState()
      Description copied from interface: IStructuredTextExpert
      Gets the state established by the last text processing call. This is null if the expert instance is not a stateful one, or if the last text processing call had nothing to pass to the next call.
      Specified by:
      getState in interface IStructuredTextExpert
      Returns:
      the last established state.
    • processSeparator

      public static void processSeparator(String text, StructuredTextCharTypes charTypes, StructuredTextOffsets offsets, int separLocation)
      See Also:
    • leanToFullText

      public String leanToFullText(String text)
      When the orientation is ORIENT_LTR and the structured text has a RTL base direction, leanToFullText adds RLE+RLM at the head of the full text and RLM+PDF at its end.

      When the orientation is ORIENT_RTL and the structured text has a LTR base direction, leanToFullText adds LRE+LRM at the head of the full text and LRM+PDF at its end.

      When the orientation is ORIENT_CONTEXTUAL_LTR or ORIENT_CONTEXTUAL_RTL and the data content would resolve to a RTL orientation while the structured text has a LTR base direction, leanToFullText adds LRM at the head of the full text.

      When the orientation is ORIENT_CONTEXTUAL_LTR or ORIENT_CONTEXTUAL_RTL and the data content would resolve to a LTR orientation while the structured text has a RTL base direction, leanToFullText adds RLM at the head of the full text.

      When the orientation is ORIENT_UNKNOWN and the structured text has a LTR base direction, leanToFullText adds LRE+LRM at the head of the full text and LRM+PDF at its end.

      When the orientation is ORIENT_UNKNOWN and the structured text has a RTL base direction, leanToFullText adds RLE+RLM at the head of the full text and RLM+PDF at its end.

      When the orientation is ORIENT_IGNORE, leanToFullText does not add any directional formatting characters as either prefix or suffix of the full text.

      Specified by:
      leanToFullText in interface IStructuredTextExpert
      Parameters:
      text - is the structured text string
      Returns:
      the structured text with directional formatting characters added to ensure correct presentation.
    • leanToFullMap

      public int[] leanToFullMap(String text)
      Description copied from interface: IStructuredTextExpert
      Given a lean string, computes the positions of each of its characters within the corresponding full string.
      Specified by:
      leanToFullMap in interface IStructuredTextExpert
      Parameters:
      text - is the structured text string.
      Returns:
      an array of integers with one element for each of the characters in the text argument, equal to the offset of the corresponding character in the full string.
    • leanBidiCharOffsets

      public int[] leanBidiCharOffsets(String text)
      Description copied from interface: IStructuredTextExpert
      Given a lean string, computes the offsets of characters before which directional formatting characters must be added in order to ensure correct presentation.

      Only LRMs (for a string with LTR base direction) and RLMs (for a string with RTL base direction) are considered. Leading and trailing LRE, RLE and PDF which might be prefixed or suffixed depending on the orientation of the GUI component used for display are not reflected in this method.

      Specified by:
      leanBidiCharOffsets in interface IStructuredTextExpert
      Parameters:
      text - is the structured text string
      Returns:
      an array of offsets to the characters in the text argument before which directional marks must be added to ensure correct presentation. The offsets are sorted in ascending order.
    • fullToLeanText

      public String fullToLeanText(String full)
      Description copied from interface: IStructuredTextExpert
      Removes directional formatting characters which were added to a structured text string to ensure correct presentation.
      Specified by:
      fullToLeanText in interface IStructuredTextExpert
      Parameters:
      full - is the structured text string including directional formatting characters.
      Returns:
      the structured text string without directional formatting characters which might have been added by processing it with IStructuredTextExpert.leanToFullText(java.lang.String).
    • fullToLeanMap

      public int[] fullToLeanMap(String full)
      Description copied from interface: IStructuredTextExpert
      Given a full string, computes the positions of each of its characters within the corresponding lean string.
      Specified by:
      fullToLeanMap in interface IStructuredTextExpert
      Parameters:
      full - is the structured text string including directional formatting characters.
      Returns:
      an array of integers with one element for each of the characters in the text argument, equal to the offset of the corresponding character in the lean string. If there is no corresponding character in the lean string (because the specified character is a directional formatting character added when invoking IStructuredTextExpert.leanToFullText(java.lang.String)), the value returned for this character is -1.
    • fullBidiCharOffsets

      public int[] fullBidiCharOffsets(String full)
      Description copied from interface: IStructuredTextExpert
      Given a full string, returns the offsets of characters which are directional formatting characters that have been added in order to ensure correct presentation.

      LRMs (for a string with LTR base direction), RLMs (for a string with RTL base direction) are considered as well as leading and trailing LRE, RLE and PDF which might be prefixed or suffixed depending on the orientation of the GUI component used for display.

      Specified by:
      fullBidiCharOffsets in interface IStructuredTextExpert
      Parameters:
      full - is the structured text string including directional formatting characters
      Returns:
      an array of offsets to the characters in the text argument which are directional formatting characters added to ensure correct presentation. The offsets are sorted in ascending order.
    • insertMarks

      public String insertMarks(String text, int[] offsets, int direction, int affixLength)
      Description copied from interface: IStructuredTextExpert
      Adds directional marks to the given text before the characters specified in the given array of offsets. It can be used to add a prefix and/or a suffix of directional formatting characters.

      The directional marks will be LRMs for structured text strings with LTR base direction and RLMs for strings with RTL base direction.

      If necessary, leading and trailing directional formatting characters (LRE, RLE and PDF) can be added depending on the value of the affix argument.

      • A value of 1 means that one LRM or RLM must be prefixed, depending on the direction. This is useful when the GUI component presenting this text has a contextual orientation.
      • A value of 2 means that LRE+LRM or RLE+RLM must be prefixed, depending on the direction, and LRM+PDF or RLM+PDF must be suffixed, depending on the direction. This is useful if the GUI component presenting this text needs to have the text orientation explicitly specified.
      • A value of 0 means that no prefix or suffix are needed.
      Specified by:
      insertMarks in interface IStructuredTextExpert
      Parameters:
      text - the structured text string
      offsets - an array of offsets to characters in text before which an LRM or RLM will be inserted. The array must be sorted in ascending order without duplicates. This argument may be null if there are no marks to add.
      direction - the base direction of the structured text. It must be one of the values IStructuredTextExpert.DIR_LTR, or IStructuredTextExpert.DIR_RTL.
      affixLength - specifies the length of prefix and suffix which should be added to the result.
      0 means no prefix or suffix
      1 means one LRM or RLM as prefix and no suffix
      2 means 2 characters in both prefix and suffix.
      Returns:
      a string corresponding to the source text with directional marks (LRMs or RLMs) added at the specified offsets, and directional formatting characters (LRE, RLE, PDF) added as prefix and suffix if so required.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object