content: package androidx.core.text;
  
  import java.nio.CharBuffer;
  import java.util.Locale;
  
  public final class TextDirectionHeuristicsCompat {
      public static final TextDirectionHeuristicCompat ANYRTL_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false);
      public static final TextDirectionHeuristicCompat FIRSTSTRONG_LTR = new TextDirectionHeuristicInternal(FirstStrong.INSTANCE, false);
      public static final TextDirectionHeuristicCompat FIRSTSTRONG_RTL = new TextDirectionHeuristicInternal(FirstStrong.INSTANCE, true);
      public static final TextDirectionHeuristicCompat LOCALE = TextDirectionHeuristicLocale.INSTANCE;
      public static final TextDirectionHeuristicCompat LTR = new TextDirectionHeuristicInternal((TextDirectionAlgorithm) null, false);
      public static final TextDirectionHeuristicCompat RTL = new TextDirectionHeuristicInternal((TextDirectionAlgorithm) null, true);
      private static final int STATE_FALSE = 1;
      private static final int STATE_TRUE = 0;
      private static final int STATE_UNKNOWN = 2;
  
      private static class AnyStrong implements TextDirectionAlgorithm {
          static final AnyStrong INSTANCE_RTL = new AnyStrong(true);
          private final boolean mLookForRtl;
  
          private AnyStrong(boolean lookForRtl) {
              this.mLookForRtl = lookForRtl;
          }
  
          public int checkRtl(CharSequence cs, int start, int count) {
              boolean z = false;
              int i = start + count;
              for (int i2 = start; i2 < i; i2++) {
                  switch (TextDirectionHeuristicsCompat.isRtlText(Character.getDirectionality(cs.charAt(i2)))) {
                      case 0:
                          if (!this.mLookForRtl) {
                              z = true;
                              break;
                          } else {
                              return 0;
                          }
                      case 1:
                          if (this.mLookForRtl) {
                              z = true;
                              break;
                          } else {
                              return 1;
                          }
                  }
              }
              if (z) {
                  return this.mLookForRtl ? 1 : 0;
              }
              return 2;
          }
      }
  
      private static class FirstStrong implements TextDirectionAlgorithm {
          static final FirstStrong INSTANCE = new FirstStrong();
  
          private FirstStrong() {
          }
  
          public int checkRtl(CharSequence cs, int start, int count) {
              int i = 2;
              int i2 = start + count;
              for (int i3 = start; i3 < i2 && i == 2; i3++) {
                  i = TextDirectionHeuristicsCompat.isRtlTextOrFormat(Character.getDirectionality(cs.charAt(i3)));
              }
              return i;
          }
      }
  
      private interface TextDirectionAlgorithm {
          int checkRtl(CharSequence charSequence, int i, int i2);
      }
  
      private static abstract class TextDirectionHeuristicImpl implements TextDirectionHeuristicCompat {
          private final TextDirectionAlgorithm mAlgorithm;
  
          TextDirectionHeuristicImpl(TextDirectionAlgorithm algorithm) {
              this.mAlgorithm = algorithm;
          }
  
          private boolean doCheck(CharSequence cs, int start, int count) {
              switch (this.mAlgorithm.checkRtl(cs, start, count)) {
                  case 0:
                      return true;
                  case 1:
                      return false;
                  default:
                      return defaultIsRtl();
              }
          }
  
          /* access modifiers changed from: protected */
          public abstract boolean defaultIsRtl();
  
          public boolean isRtl(CharSequence cs, int start, int count) {
              if (cs != null && start >= 0 && count >= 0 && cs.length() - count >= start) {
                  return this.mAlgorithm == null ? defaultIsRtl() : doCheck(cs, start, count);
              }
              throw new IllegalArgumentException();
          }
  
          public boolean isRtl(char[] array, int start, int count) {
              return isRtl((CharSequence) CharBuffer.wrap(array), start, count);
          }
      }
  
      private static class TextDirectionHeuristicInternal extends TextDirectionHeuristicImpl {
          private final boolean mDefaultIsRtl;
  
          TextDirectionHeuristicInternal(TextDirectionAlgorithm algorithm, boolean defaultIsRtl) {
              super(algorithm);
              this.mDefaultIsRtl = defaultIsRtl;
          }
  
          /* access modifiers changed from: protected */
          public boolean defaultIsRtl() {
              return this.mDefaultIsRtl;
          }
      }
  
      private static class TextDirectionHeuristicLocale extends TextDirectionHeuristicImpl {
          static final TextDirectionHeuristicLocale INSTANCE = new TextDirectionHeuristicLocale();
  
          TextDirectionHeuristicLocale() {
              super((TextDirectionAlgorithm) null);
          }
  
          /* access modifiers changed from: protected */
          public boolean defaultIsRtl() {
              return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
          }
      }
  
      private TextDirectionHeuristicsCompat() {
      }
  
      static int isRtlText(int directionality) {
          switch (directionality) {
              case 0:
                  return 1;
              case 1:
              case 2:
                  return 0;
              default:
                  return 2;
          }
      }
  
      static int isRtlTextOrFormat(int directionality) {
          switch (directionality) {
              case 0:
              case 14:
              case 15:
                  return 1;
              case 1:
              case 2:
              case 16:
              case 17:
                  return 0;
              default:
                  return 2;
          }
      }
  }
  