org.eclipse.equinox.bidi_0.9.100.v20121107-021609

16:43:46.712 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.bidi_0.9.100.v20121107-021609.jar
package org.eclipse.equinox.bidi;

import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
import org.eclipse.equinox.bidi.advanced.STextExpertFactory;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;

public final class STextProcessor
{
  private static final String defaultSeparators = ".:/\\";
  private static final char LRM = '?';
  private static final char LRE = '?';
  private static final char RLE = '?';
  private static final char PDF = '?';
  
  public static String process(String str)
  {
    return process(str, ".:/\\");
  }
  
  public static String process(String str, String separators)
  {
    if ((str == null) || (str.length() <= 1)) {
      return str;
    }
    if ((str.charAt(0) == '?') && (str.charAt(str.length() - 1) == '?')) {
      return str;
    }
    STextEnvironment env = new STextEnvironment(null, false, 4);
    if (!env.isProcessingNeeded()) {
      return str;
    }
    boolean isStringBidi = false;
    int strLength = str.length();
    for (int i = 0; i < strLength; i++)
    {
      char c = str.charAt(i);
      if (((c >= '?') && (c <= '?')) || ((c >= 64285) && (c <= 65276)))
      {
        isStringBidi = true;
        break;
      }
    }
    if ((!isStringBidi) && 
      (Character.isLetter(str.charAt(0))))
    {
      char c = str.charAt(strLength - 1);
      if ((Character.isDigit(c)) || (Character.isLetter(c))) {
        return str;
      }
    }
    if (separators == null) {
      separators = ".:/\\";
    }
    STextTypeHandler handler = new STextTypeHandler(separators);
    ISTextExpert expert = STextExpertFactory.getStatefulExpert(handler, env);
    return expert.leanToFullText(str);
  }
  
  public static String processTyped(String str, String textType)
  {
    if ((str == null) || (str.length() <= 1)) {
      return str;
    }
    char c = str.charAt(0);
    if (((c == '?') || (c == '?')) && (str.charAt(str.length() - 1) == '?')) {
      return str;
    }
    STextEnvironment env = new STextEnvironment(null, false, 4);
    if (!env.isProcessingNeeded()) {
      return str;
    }
    ISTextExpert expert = STextExpertFactory.getExpert(textType, env);
    return expert.leanToFullText(str);
  }
  
  public static String deprocess(String str)
  {
    if ((str == null) || (str.length() <= 1)) {
      return str;
    }
    STextEnvironment env = new STextEnvironment(null, false, 4);
    if (!env.isProcessingNeeded()) {
      return str;
    }
    StringBuffer buf = new StringBuffer();
    int strLen = str.length();
    for (int i = 0; i < strLen; i++)
    {
      char c = str.charAt(i);
      switch (c)
      {
      case '?': 
        break;
      case '?': 
        break;
      case '?': 
        break;
      default: 
        buf.append(c);
      }
    }
    return buf.toString();
  }
  
  public static String deprocessTyped(String str, String textType)
  {
    if ((str == null) || (str.length() <= 1)) {
      return str;
    }
    STextEnvironment env = new STextEnvironment(null, false, 4);
    if (!env.isProcessingNeeded()) {
      return str;
    }
    ISTextExpert expert = STextExpertFactory.getExpert(textType, env);
    return expert.fullToLeanText(str);
  }
  
  public static String getDefaultSeparators()
  {
    return ".:/\\";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.STextProcessor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi;

import org.eclipse.equinox.bidi.custom.STextTypeHandler;
import org.eclipse.equinox.bidi.internal.STextTypesCollector;

public final class STextTypeHandlerFactory
{
  public static final String PROPERTY = "property";
  public static final String UNDERSCORE = "underscore";
  public static final String COMMA_DELIMITED = "comma";
  public static final String SYSTEM_USER = "system";
  public static final String FILE = "file";
  public static final String EMAIL = "email";
  public static final String URL = "url";
  public static final String REGEXP = "regex";
  public static final String XPATH = "xpath";
  public static final String JAVA = "java";
  public static final String SQL = "sql";
  public static final String RTL_ARITHMETIC = "math";
  
  public static STextTypeHandler getHandler(String id)
  {
    return STextTypesCollector.getInstance().getHandler(id);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.STextTypeHandlerFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.advanced;

import org.eclipse.equinox.bidi.custom.STextTypeHandler;

public abstract interface ISTextExpert
{
  public static final int DIR_LTR = 0;
  public static final int DIR_RTL = 1;
  
  public abstract STextTypeHandler getTypeHandler();
  
  public abstract STextEnvironment getEnvironment();
  
  public abstract String leanToFullText(String paramString);
  
  public abstract int[] leanToFullMap(String paramString);
  
  public abstract int[] leanBidiCharOffsets(String paramString);
  
  public abstract String fullToLeanText(String paramString);
  
  public abstract int[] fullToLeanMap(String paramString);
  
  public abstract int[] fullBidiCharOffsets(String paramString);
  
  public abstract String insertMarks(String paramString, int[] paramArrayOfInt, int paramInt1, int paramInt2);
  
  public abstract int getTextDirection(String paramString);
  
  public abstract void setState(Object paramObject);
  
  public abstract Object getState();
  
  public abstract void clearState();
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.advanced.ISTextExpert
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.advanced;

import java.util.Locale;
import org.eclipse.equinox.bidi.internal.STextActivator;

public class STextEnvironment
{
  public static final int ORIENT_LTR = 0;
  public static final int ORIENT_RTL = 1;
  public static final int ORIENT_CONTEXTUAL = 2;
  public static final int ORIENT_CONTEXTUAL_LTR = 2;
  public static final int ORIENT_CONTEXTUAL_RTL = 3;
  public static final int ORIENT_UNKNOWN = 4;
  public static final int ORIENT_IGNORE = 8;
  public static final STextEnvironment DEFAULT = new STextEnvironment(null, false, 0);
  private final String language;
  private final boolean mirrored;
  private final int orientation;
  private Boolean processingNeeded;
  
  public STextEnvironment(String lang, boolean mirrored, int orientation)
  {
    if (lang != null)
    {
      if (lang.length() > 2) {
        language = lang.substring(0, 2);
      } else {
        language = lang;
      }
    }
    else {
      language = STextActivator.getInstance().getDefaultLocale().getLanguage();
    }
    this.mirrored = mirrored;
    this.orientation = ((orientation >= 0) && (orientation <= 8) ? orientation : 4);
  }
  
  public String getLanguage()
  {
    return language;
  }
  
  public boolean getMirrored()
  {
    return mirrored;
  }
  
  public int getOrientation()
  {
    return orientation;
  }
  
  public boolean isProcessingNeeded()
  {
    if (processingNeeded == null)
    {
      String osName = STextActivator.getInstance().getProperty("os.name");
      if (osName != null) {
        osName = osName.toLowerCase();
      }
      boolean supportedOS = (osName.startsWith("windows")) || (osName.startsWith("linux")) || (osName.startsWith("mac"));
      if (supportedOS)
      {
        boolean isBidi = ("iw".equals(language)) || 
          ("he".equals(language)) || 
          ("ar".equals(language)) || 
          ("fa".equals(language)) || 
          ("ur".equals(language));
        processingNeeded = new Boolean(isBidi);
      }
      else
      {
        processingNeeded = new Boolean(false);
      }
    }
    return processingNeeded.booleanValue();
  }
  
  public int hashCode()
  {
    int result = 1;
    result = 31 * result + (language == null ? 0 : language.hashCode());
    result = 31 * result + (mirrored ? 1231 : 1237);
    result = 31 * result + orientation;
    result = 31 * result + (processingNeeded == null ? 0 : processingNeeded.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    STextEnvironment other = (STextEnvironment)obj;
    if (language == null)
    {
      if (language != null) {
        return false;
      }
    }
    else if (!language.equals(language)) {
      return false;
    }
    if (mirrored != mirrored) {
      return false;
    }
    if (orientation != orientation) {
      return false;
    }
    if (processingNeeded == null)
    {
      if (processingNeeded != null) {
        return false;
      }
    }
    else if (!processingNeeded.equals(processingNeeded)) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.advanced.STextEnvironment
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.advanced;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.equinox.bidi.STextProcessor;
import org.eclipse.equinox.bidi.STextTypeHandlerFactory;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;
import org.eclipse.equinox.bidi.internal.STextImpl;

public final class STextExpertFactory
{
  private static final String defaultSeparators = ;
  private static Map sharedDefaultExperts = new HashMap();
  private static Map sharedExperts = new HashMap();
  private static ISTextExpert defaultExpert;
  
  public static ISTextExpert getExpert()
  {
    if (defaultExpert == null)
    {
      STextTypeHandler handler = new STextTypeHandler(defaultSeparators);
      defaultExpert = new STextImpl(handler, STextEnvironment.DEFAULT, false);
    }
    return defaultExpert;
  }
  
  public static ISTextExpert getExpert(String type)
  {
    synchronized (sharedDefaultExperts)
    {
      ISTextExpert expert = (ISTextExpert)sharedDefaultExperts.get(type);
      if (expert == null)
      {
        STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
        if (handler == null) {
          throw new IllegalArgumentException("Invalid type argument");
        }
        expert = new STextImpl(handler, STextEnvironment.DEFAULT, false);
        sharedDefaultExperts.put(type, expert);
      }
    }
    ISTextExpert expert;
    return expert;
  }
  
  public static ISTextExpert getExpert(String type, STextEnvironment environment)
  {
    if (environment == null) {
      environment = STextEnvironment.DEFAULT;
    }
    synchronized (sharedExperts)
    {
      Map experts = (Map)sharedExperts.get(type);
      if (experts == null)
      {
        experts = new HashMap();
        sharedExperts.put(type, experts);
      }
      ISTextExpert expert = (ISTextExpert)experts.get(environment);
      if (expert == null)
      {
        STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
        if (handler == null) {
          throw new IllegalArgumentException("Invalid type argument");
        }
        expert = new STextImpl(handler, environment, false);
        experts.put(type, expert);
      }
    }
    ISTextExpert expert;
    return expert;
  }
  
  public static ISTextExpert getStatefulExpert(String type)
  {
    return getStatefulExpert(type, STextEnvironment.DEFAULT);
  }
  
  public static ISTextExpert getStatefulExpert(String type, STextEnvironment environment)
  {
    STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
    if (handler == null) {
      throw new IllegalArgumentException("Invalid type argument");
    }
    return getStatefulExpert(handler, environment);
  }
  
  public static ISTextExpert getStatefulExpert(STextTypeHandler handler, STextEnvironment environment)
  {
    if (environment == null) {
      environment = STextEnvironment.DEFAULT;
    }
    return new STextImpl(handler, environment, true);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.advanced.STextExpertFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.custom;

import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;

public class STextCharTypes
{
  static final byte B = 10;
  static final byte L = 0;
  static final byte R = 1;
  static final byte AL = 2;
  static final byte AN = 6;
  static final byte EN = 3;
  private static final int CHARTYPES_ADD = 2;
  protected final ISTextExpert expert;
  protected final STextTypeHandler handler;
  protected final STextEnvironment environment;
  protected final String text;
  private byte[] types;
  private int direction = -1;
  
  public STextCharTypes(ISTextExpert expert, String text)
  {
    this.expert = expert;
    handler = expert.getTypeHandler();
    environment = expert.getEnvironment();
    this.text = text;
    types = new byte[text.length()];
  }
  
  public int getDirection()
  {
    if (direction < 0) {
      direction = handler.getDirection(expert, text, this);
    }
    return direction;
  }
  
  private byte getCachedTypeAt(int index)
  {
    return (byte)(types[index] - 2);
  }
  
  private boolean hasCachedTypeAt(int i)
  {
    return types[i] != 0;
  }
  
  public byte getBidiTypeAt(int index)
  {
    if (hasCachedTypeAt(index)) {
      return getCachedTypeAt(index);
    }
    byte charType = Character.getDirectionality(text.charAt(index));
    if (charType == 10)
    {
      if (direction < 0)
      {
        if (direction < -1) {
          return charType;
        }
        direction = -2;
        direction = handler.getDirection(expert, text, this);
      }
      charType = direction == 1 ? 1 : 0;
    }
    setBidiTypeAt(index, charType);
    return charType;
  }
  
  public void setBidiTypeAt(int index, byte charType)
  {
    types[index] = ((byte)(charType + 2));
  }
  
  public int resolveOrientation()
  {
    int orient = environment.getOrientation();
    if ((orient & 0x2) == 0) {
      return orient;
    }
    orient &= 0xFFFFFFFD;
    int len = text.length();
    for (int i = 0; i < len; i++)
    {
      byte charType;
      if (!hasCachedTypeAt(i))
      {
        byte charType = Character.getDirectionality(text.charAt(i));
        if (charType == 10) {
          continue;
        }
        setBidiTypeAt(i, charType);
      }
      else
      {
        charType = getCachedTypeAt(i);
      }
      if (charType == 0) {
        return 0;
      }
      if ((charType == 1) || (charType == 2)) {
        return 1;
      }
    }
    return orient;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.custom.STextCharTypes
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.custom;

public class STextOffsets
{
  private static final byte L = 0;
  private static final byte R = 1;
  private static final byte AL = 2;
  private static final byte AN = 6;
  private static final byte EN = 3;
  private static final byte[] STRONGS = { 01 };
  private static final int OFFSET_SIZE = 20;
  private int[] offsets = new int[20];
  private int count;
  private int direction = -1;
  private int prefixLength;
  
  public int getPrefixLength()
  {
    return prefixLength;
  }
  
  public void setPrefixLength(int prefLen)
  {
    prefixLength = prefLen;
  }
  
  public int getCount()
  {
    return count;
  }
  
  public void clear()
  {
    count = 0;
  }
  
  public int getOffset(int index)
  {
    return offsets[index];
  }
  
  public void insertOffset(STextCharTypes charTypes, int offset)
  {
    if (count >= offsets.length)
    {
      int[] newOffsets = new int[offsets.length * 2];
      System.arraycopy(offsets, 0, newOffsets, 0, count);
      offsets = newOffsets;
    }
    int index = count - 1;
    while (index >= 0)
    {
      int wrkOffset = offsets[index];
      if (offset > wrkOffset) {
        break;
      }
      if (offset == wrkOffset) {
        return;
      }
      index--;
    }
    index++;
    int length = count - index;
    if (length > 0) {
      System.arraycopy(offsets, index, offsets, index + 1, length);
    }
    offsets[index] = offset;
    count += 1;
    if (offset < 1) {
      return;
    }
    if (charTypes == null) {
      return;
    }
    byte charType = charTypes.getBidiTypeAt(offset);
    if ((charType == 0) || (charType == 1) || (charType == 2) || (charType == 3) || (charType == 6)) {
      index = offset - 1;
    } else {
      index = offset;
    }
    if (direction < 0) {
      direction = charTypes.getDirection();
    }
    charTypes.setBidiTypeAt(index, STRONGS[direction]);
  }
  
  public int[] getOffsets()
  {
    if (count == offsets.length) {
      return offsets;
    }
    int[] array = new int[count];
    System.arraycopy(offsets, 0, array, 0, count);
    return array;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.custom.STextOffsets
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.custom;

import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.internal.STextImpl;

public class STextTypeHandler
{
  private final String separators;
  
  public STextTypeHandler()
  {
    separators = "";
  }
  
  public STextTypeHandler(String separators)
  {
    this.separators = separators;
  }
  
  public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex)
  {
    throw new IllegalStateException("A handler with specialsCount > 0 must have an indexOfSpecial() method.");
  }
  
  public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation)
  {
    throw new IllegalStateException("A handler with specialsCount > 0 must have a processSpecial() method.");
  }
  
  public static final void insertMark(String text, STextCharTypes charTypes, STextOffsets offsets, int offset)
  {
    offsets.insertOffset(charTypes, offset);
  }
  
  public static final void processSeparator(String text, STextCharTypes charTypes, STextOffsets offsets, int separLocation)
  {
    STextImpl.processSeparator(text, charTypes, offsets, separLocation);
  }
  
  public String getSeparators(ISTextExpert expert)
  {
    return separators;
  }
  
  public int getDirection(ISTextExpert expert, String text)
  {
    return 0;
  }
  
  public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes)
  {
    return 0;
  }
  
  public int getSpecialsCount(ISTextExpert expert)
  {
    return 0;
  }
  
  public boolean skipProcessing(ISTextExpert expert, String text, STextCharTypes charTypes)
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.custom.STextTypeHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.internal;

import java.io.PrintStream;
import java.util.Locale;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.service.localization.LocaleProvider;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

public class STextActivator
  implements BundleActivator
{
  private ServiceTracker logTracker = null;
  private BundleContext bundleContext;
  private static STextActivator instance;
  
  public STextActivator()
  {
    instance = this;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    bundleContext = context;
    instance = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    if (logTracker != null)
    {
      logTracker.close();
      logTracker = null;
    }
    bundleContext = null;
  }
  
  public static STextActivator getInstance()
  {
    return instance;
  }
  
  public String getProperty(String key)
  {
    return bundleContext.getProperty(key);
  }
  
  public Locale getDefaultLocale()
  {
    ServiceReference[] references = null;
    try
    {
      references = bundleContext.getAllServiceReferences(null, LocaleProvider.class.getName());
    }
    catch (InvalidSyntaxException localInvalidSyntaxException) {}
    if ((references == null) || (references.length < 1)) {
      return Locale.getDefault();
    }
    Object service = bundleContext.getService(references[0]);
    LocaleProvider localeProvider = (LocaleProvider)service;
    if (localeProvider != null)
    {
      Locale currentLocale = localeProvider.getLocale();
      bundleContext.ungetService(references[0]);
      if (currentLocale != null) {
        return currentLocale;
      }
    }
    return Locale.getDefault();
  }
  
  private FrameworkLog getFrameworkLog()
  {
    if (logTracker == null)
    {
      logTracker = new ServiceTracker(bundleContext, FrameworkLog.class.getName(), null);
      logTracker.open();
    }
    return (FrameworkLog)logTracker.getService();
  }
  
  public static void logError(String message, Exception e)
  {
    FrameworkLog frameworkLog = instance.getFrameworkLog();
    if (frameworkLog != null)
    {
      frameworkLog.log(new FrameworkLogEntry("org.eclipse.equinox.bidi", 4, 1, message, 0, e, null));
      return;
    }
    System.err.println(message);
    if (e != null) {
      e.printStackTrace();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.internal.STextActivator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.internal;

import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.custom.STextCharTypes;
import org.eclipse.equinox.bidi.custom.STextOffsets;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;

public abstract class STextDelims
  extends STextTypeHandler
{
  public STextDelims() {}
  
  public STextDelims(String separators)
  {
    super(separators);
  }
  
  public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex)
  {
    char delim = getDelimiters().charAt((caseNumber - 1) * 2);
    return text.indexOf(delim, fromIndex);
  }
  
  public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation)
  {
    STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
    int loc = separLocation + 1;
    char delim = getDelimiters().charAt(caseNumber * 2 - 1);
    loc = text.indexOf(delim, loc);
    if (loc < 0) {
      return text.length();
    }
    return loc + 1;
  }
  
  protected abstract String getDelimiters();
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.internal.STextDelims
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.internal;

import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.custom.STextCharTypes;
import org.eclipse.equinox.bidi.custom.STextOffsets;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;

public abstract class STextDelimsEsc
  extends STextDelims
{
  public STextDelimsEsc() {}
  
  public STextDelimsEsc(String separator)
  {
    super(separator);
  }
  
  public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation)
  {
    STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
    int location = separLocation + 1;
    char delim = getDelimiters().charAt(caseNumber * 2 - 1);
    int cnt;
    do
    {
      location = text.indexOf(delim, location);
      if (location < 0) {
        return text.length();
      }
      cnt = 0;
      for (int i = location - 1; text.charAt(i) == '\\'; i--) {
        cnt++;
      }
      location++;
    } while ((cnt & 0x1) != 0);
    return location;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.internal.STextDelimsEsc
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.internal;

import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
import org.eclipse.equinox.bidi.custom.STextCharTypes;
import org.eclipse.equinox.bidi.custom.STextOffsets;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;

public class STextImpl
  implements ISTextExpert
{
  static final String EMPTY_STRING = "";
  static final byte B = 10;
  static final byte L = 0;
  static final byte R = 1;
  static final byte AL = 2;
  static final byte AN = 6;
  static final byte EN = 3;
  static final char LRM = '?';
  static final char RLM = '?';
  static final char LRE = '?';
  static final char RLE = '?';
  static final char PDF = '?';
  static final char[] MARKS = { '?', '?' };
  static final char[] EMBEDS = { '?', '?' };
  static final int PREFIX_LENGTH = 2;
  static final int SUFFIX_LENGTH = 2;
  static final int FIXES_LENGTH = 4;
  static final int[] EMPTY_INT_ARRAY = new int[0];
  protected final STextTypeHandler handler;
  protected final STextEnvironment environment;
  protected final boolean sharedExpert;
  protected Object state;
  
  public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, boolean shared)
  {
    handler = structuredTextHandler;
    this.environment = environment;
    sharedExpert = shared;
  }
  
  public STextTypeHandler getTypeHandler()
  {
    return handler;
  }
  
  public STextEnvironment getEnvironment()
  {
    return environment;
  }
  
  public int getTextDirection(String text)
  {
    return handler.getDirection(this, text);
  }
  
  public void clearState()
  {
    if (sharedExpert) {
      state = null;
    }
  }
  
  public void setState(Object newState)
  {
    if (sharedExpert) {
      state = newState;
    }
  }
  
  public Object getState()
  {
    return state;
  }
  
  long computeNextLocation(String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos)
  {
    String separators = handler.getSeparators(this);
    int separCount = separators.length();
    int specialsCount = handler.getSpecialsCount(this);
    int len = text.length();
    int nextLocation = len;
    int idxLocation = 0;
    for (int i = 0; i < specialsCount; i++)
    {
      int location = locations[(separCount + i)];
      if (location < curPos)
      {
        location = handler.indexOfSpecial(this, text, charTypes, offsets, i + 1, curPos);
        if (location < 0) {
          location = len;
        }
        locations[(separCount + i)] = location;
      }
      if (location < nextLocation)
      {
        nextLocation = location;
        idxLocation = separCount + i;
      }
    }
    for (int i = 0; i < separCount; i++)
    {
      int location = locations[i];
      if (location < curPos)
      {
        location = text.indexOf(separators.charAt(i), curPos);
        if (location < 0) {
          location = len;
        }
        locations[i] = location;
      }
      if (location < nextLocation)
      {
        nextLocation = location;
        idxLocation = i;
      }
    }
    return nextLocation + (idxLocation << 32);
  }
  
  public static void processSeparator(String text, STextCharTypes charTypes, STextOffsets offsets, int separLocation)
  {
    int len = text.length();
    int direction = charTypes.getDirection();
    if (direction == 1)
    {
      for (int i = separLocation - 1; i >= 0; i--)
      {
        byte charType = charTypes.getBidiTypeAt(i);
        if ((charType == 1) || (charType == 2)) {
          return;
        }
        if (charType == 0)
        {
          for (int j = separLocation; j < len; j++)
          {
            charType = charTypes.getBidiTypeAt(j);
            if ((charType == 1) || (charType == 2)) {
              return;
            }
            if ((charType == 0) || (charType == 3))
            {
              offsets.insertOffset(charTypes, separLocation);
              return;
            }
          }
          return;
        }
      }
      return;
    }
    boolean doneAN = false;
    for (int i = separLocation - 1; i >= 0; i--)
    {
      byte charType = charTypes.getBidiTypeAt(i);
      if (charType == 0) {
        return;
      }
      if ((charType == 1) || (charType == 2))
      {
        for (int j = separLocation; j < len; j++)
        {
          charType = charTypes.getBidiTypeAt(j);
          if (charType == 0) {
            return;
          }
          if ((charType == 1) || (charType == 3) || (charType == 2) || (charType == 6))
          {
            offsets.insertOffset(charTypes, separLocation);
            return;
          }
        }
        return;
      }
      if ((charType == 6) && (!doneAN))
      {
        for (int j = separLocation; j < len; j++)
        {
          charType = charTypes.getBidiTypeAt(j);
          if (charType == 0) {
            return;
          }
          if ((charType == 2) || (charType == 6) || (charType == 1))
          {
            offsets.insertOffset(charTypes, separLocation);
            return;
          }
        }
        doneAN = true;
      }
    }
  }
  
  public String leanToFullText(String text)
  {
    int len = text.length();
    if (len == 0) {
      return text;
    }
    STextCharTypes charTypes = new STextCharTypes(this, text);
    STextOffsets offsets = leanToFullCommon(text, charTypes);
    int prefixLength = offsets.getPrefixLength();
    int direction = charTypes.getDirection();
    return insertMarks(text, offsets.getOffsets(), direction, prefixLength);
  }
  
  public int[] leanToFullMap(String text)
  {
    int len = text.length();
    if (len == 0) {
      return EMPTY_INT_ARRAY;
    }
    STextCharTypes charTypes = new STextCharTypes(this, text);
    STextOffsets offsets = leanToFullCommon(text, charTypes);
    int prefixLength = offsets.getPrefixLength();
    int[] map = new int[len];
    int count = offsets.getCount();
    int added = prefixLength;
    int pos = 0;
    for (int i = 0; pos < len; pos++)
    {
      if ((i < count) && (pos == offsets.getOffset(i)))
      {
        added++;
        i++;
      }
      map[pos] = (pos + added);
    }
    return map;
  }
  
  public int[] leanBidiCharOffsets(String text)
  {
    int len = text.length();
    if (len == 0) {
      return EMPTY_INT_ARRAY;
    }
    STextCharTypes charTypes = new STextCharTypes(this, text);
    STextOffsets offsets = leanToFullCommon(text, charTypes);
    return offsets.getOffsets();
  }
  
  private STextOffsets leanToFullCommon(String text, STextCharTypes charTypes)
  {
    int len = text.length();
    int direction = handler.getDirection(this, text, charTypes);
    STextOffsets offsets = new STextOffsets();
    if (!handler.skipProcessing(this, text, charTypes))
    {
      int separCount = handler.getSeparators(this).length();
      int[] locations = new int[separCount + handler.getSpecialsCount(this)];
      int i = 0;
      for (int k = locations.length; i < k; i++) {
        locations[i] = -1;
      }
      int curPos = 0;
      if (state != null) {
        curPos = handler.processSpecial(this, text, charTypes, offsets, 0, -1);
      }
      do
      {
        long res = computeNextLocation(text, charTypes, offsets, locations, curPos);
        int nextLocation = (int)(res & 0xFFFFFFFFFFFFFFFF);
        if (nextLocation >= len) {
          break;
        }
        int idxLocation = (int)(res >> 32);
        if (idxLocation < separCount)
        {
          processSeparator(text, charTypes, offsets, nextLocation);
          curPos = nextLocation + 1;
        }
        else
        {
          idxLocation -= separCount - 1;
          curPos = handler.processSpecial(this, text, charTypes, offsets, idxLocation, nextLocation);
        }
      } while (curPos < len);
    }
    int orientation = environment.getOrientation();
    int prefixLength;
    int prefixLength;
    if (orientation == 8)
    {
      prefixLength = 0;
    }
    else
    {
      int resolvedOrientation = charTypes.resolveOrientation();
      int prefixLength;
      if ((orientation != 4) && (resolvedOrientation == direction))
      {
        prefixLength = 0;
      }
      else
      {
        int prefixLength;
        if ((orientation & 0x2) != 0) {
          prefixLength = 1;
        } else {
          prefixLength = 2;
        }
      }
    }
    offsets.setPrefixLength(prefixLength);
    return offsets;
  }
  
  public String fullToLeanText(String full)
  {
    if (full.length() == 0) {
      return full;
    }
    int dir = handler.getDirection(this, full);
    char curMark = MARKS[dir];
    char curEmbed = EMBEDS[dir];
    
    int lenFull = full.length();
    for (int i = 0; i < lenFull; i++)
    {
      char c = full.charAt(i);
      if ((c != curEmbed) && (c != curMark)) {
        break;
      }
    }
    if (i > 0)
    {
      full = full.substring(i);
      lenFull = full.length();
    }
    for (i = lenFull - 1; i >= 0; i--)
    {
      char c = full.charAt(i);
      if ((c != '?') && (c != curMark)) {
        break;
      }
    }
    if (i < 0) {
      return "";
    }
    if (i < lenFull - 1)
    {
      full = full.substring(0, i + 1);
      lenFull = full.length();
    }
    char[] chars = full.toCharArray();
    
    int cnt = 0;
    for (i = 0; i < lenFull; i++)
    {
      char c = chars[i];
      if (c == curMark) {
        cnt++;
      } else if (cnt > 0) {
        chars[(i - cnt)] = c;
      }
    }
    String lean = new String(chars, 0, lenFull - cnt);
    String full2 = leanToFullText(lean);
    
    int beginIndex = 0;int endIndex = full2.length();
    if (full2.charAt(0) == curMark)
    {
      beginIndex = 1;
    }
    else
    {
      if (full2.charAt(0) == curEmbed)
      {
        beginIndex = 1;
        if (full2.charAt(0) == curMark) {
          beginIndex = 2;
        }
      }
      if (full2.charAt(endIndex - 1) == '?')
      {
        endIndex--;
        if (full2.charAt(endIndex - 1) == curMark) {
          endIndex--;
        }
      }
    }
    if ((beginIndex > 0) || (endIndex < full2.length())) {
      full2 = full2.substring(beginIndex, endIndex);
    }
    if (full2.equals(full)) {
      return lean;
    }
    char[] newChars = new char[lenFull];
    
    int lenFull2 = full2.length();
    int newCharsPos;
    int idxLean;
    int idxFull2;
    int idxFull = idxFull2 = idxLean = newCharsPos = 0;
    while ((idxFull < lenFull) && (idxFull2 < lenFull2))
    {
      char cFull2 = full2.charAt(idxFull2);
      char cFull = full.charAt(idxFull);
      if (cFull2 == cFull)
      {
        if (cFull2 != curMark) {
          newChars[(newCharsPos++)] = chars[(idxLean++)];
        }
        idxFull++;
        idxFull2++;
      }
      else if (cFull2 == curMark)
      {
        idxFull2++;
      }
      else if (cFull == curMark)
      {
        idxFull++;
        if (full.charAt(idxFull - 2) != curMark) {
          newChars[(newCharsPos++)] = curMark;
        }
      }
      else
      {
        throw new IllegalStateException("Internal error: extra character not a Mark.");
      }
    }
    if (idxFull < lenFull) {
      throw new IllegalStateException("Internal error: unexpected EOL.");
    }
    lean = new String(newChars, 0, newCharsPos);
    return lean;
  }
  
  public int[] fullToLeanMap(String full)
  {
    int lenFull = full.length();
    if (lenFull == 0) {
      return EMPTY_INT_ARRAY;
    }
    String lean = fullToLeanText(full);
    int lenLean = lean.length();
    int dir = handler.getDirection(this, lean);
    char curMark = MARKS[dir];
    char curEmbed = EMBEDS[dir];
    int[] map = new int[lenFull];
    for (int idxFull = 0; idxFull < lenFull; idxFull++)
    {
      char c = full.charAt(idxFull);
      if ((c != curEmbed) && (c != curMark)) {
        break;
      }
      map[idxFull] = -1;
    }
    for (int idxLean = 0; idxLean < lenLean; idxFull++) {
      if (full.charAt(idxFull) == lean.charAt(idxLean))
      {
        map[idxFull] = idxLean;
        idxLean++;
      }
      else
      {
        map[idxFull] = -1;
      }
    }
    for (; idxFull < lenFull; idxFull++) {
      map[idxFull] = -1;
    }
    return map;
  }
  
  public int[] fullBidiCharOffsets(String full)
  {
    int lenFull = full.length();
    if (lenFull == 0) {
      return EMPTY_INT_ARRAY;
    }
    String lean = fullToLeanText(full);
    STextOffsets offsets = new STextOffsets();
    int lenLean = lean.length();
    int idxFull;
    for (int idxLean = idxFull = 0; idxLean < lenLean; idxFull++) {
      if (full.charAt(idxFull) == lean.charAt(idxLean)) {
        idxLean++;
      } else {
        offsets.insertOffset(null, idxFull);
      }
    }
    for (; idxFull < lenFull; idxFull++) {
      offsets.insertOffset(null, idxFull);
    }
    return offsets.getOffsets();
  }
  
  public String insertMarks(String text, int[] offsets, int direction, int affixLength)
  {
    if ((direction != 0) && (direction != 1)) {
      throw new IllegalArgumentException("Invalid direction");
    }
    if ((affixLength < 0) || (affixLength > 2)) {
      throw new IllegalArgumentException("Invalid affix length");
    }
    int count = offsets == null ? 0 : offsets.length;
    if ((count == 0) && (affixLength == 0)) {
      return text;
    }
    int textLength = text.length();
    if (textLength == 0) {
      return text;
    }
    int newLen = textLength + count;
    if (affixLength == 1) {
      newLen++;
    } else if (affixLength == 2) {
      newLen += 4;
    }
    char[] fullChars = new char[newLen];
    int added = affixLength;
    
    char curMark = MARKS[direction];
    int i = 0;
    for (int j = 0; i < textLength; i++)
    {
      char c = text.charAt(i);
      if ((j < count) && (i == offsets[j]))
      {
        fullChars[(i + added)] = curMark;
        added++;
        j++;
      }
      fullChars[(i + added)] = c;
    }
    if (affixLength > 0) {
      if (affixLength == 1)
      {
        fullChars[0] = curMark;
      }
      else
      {
        char curEmbed = EMBEDS[direction];
        fullChars[0] = curEmbed;
        fullChars[1] = curMark;
        fullChars[(newLen - 1)] = '?';
        fullChars[(newLen - 2)] = curMark;
      }
    }
    return new String(fullChars);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.internal.STextImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.internal;

import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.custom.STextCharTypes;
import org.eclipse.equinox.bidi.custom.STextOffsets;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;

public class STextSingle
  extends STextTypeHandler
{
  public STextSingle(String separator)
  {
    super(separator);
  }
  
  public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex)
  {
    return text.indexOf(getSeparators(expert).charAt(0), fromIndex);
  }
  
  public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation)
  {
    STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
    return text.length();
  }
  
  public int getSpecialsCount(ISTextExpert expert)
  {
    return 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.bidi.internal.STextSingle
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.bidi.internal;

import java.lang.ref.SoftReference;

public class STextStringRecord
{
  pu
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd