private boolean parseMtdt(BoxHeader header) {
   // if mCurrentBoxSequence contains trak, then add metadata to current
   // track
   // else metadata is for file
   // we're currently not interested in anything on track level
   try {
     int numberOfUnits = mDataSource.readShort();
     mHmmpTitles = new ArrayList<>(1);
     ArrayDeque<String> titleLanguages = new ArrayDeque<>(1);
     ArrayDeque<String> iconLanguages = new ArrayDeque<>(1);
     for (int i = 0; i < numberOfUnits; i++) {
       short dataUnitSize = mDataSource.readShort();
       int dataTypeID = mDataSource.readInt();
       short language = mDataSource.readShort();
       char l1 = Character.toChars(((language >> 10) & 0x1F) + 96)[0];
       char l2 = Character.toChars(((language >> 5) & 0x1F) + 96)[0];
       char l3 = Character.toChars(((language) & 0x1F) + 96)[0];
       String languageString = "" + l1 + l2 + l3;
       short encodingType = mDataSource.readShort();
       if (encodingType == 0x01) {
         byte[] metadata = new byte[dataUnitSize - 10];
         mDataSource.read(metadata);
         String metadataString = new String(metadata, "UTF-16BE").trim();
         if ((dataTypeID & 0xFFFF) == 0x01) {
           mHmmpTitles.add(metadataString);
           titleLanguages.add(languageString);
         }
       } else if (encodingType == 0x101) {
         if (dataTypeID == 0xA04) {
           if (mIconList == null) {
             mIconList = new ArrayList<>();
           }
           mDataSource.skipBytes(4); // selectionFlags
           mDataSource.skipBytes(4); // reserved
           int artworkCount = mDataSource.readInt();
           for (int j = 0; j < artworkCount; j++) {
             IconInfo iconInfo = new IconInfo();
             iconInfo.mtsmId = mDataSource.readInt();
             iconInfo.mdstIndex = mDataSource.readInt();
             iconInfo.languageIndex = iconLanguages.size();
             mDataSource.skipBytes(4);
             mIconList.add(iconInfo);
           }
           iconLanguages.add(languageString);
         }
       }
     }
     addMetaDataValue(KEY_HMMP_TITLE_LANGUAGES, titleLanguages.toArray());
     addMetaDataValue(KEY_HMMP_ICON_LANGUAGES, iconLanguages.toArray());
   } catch (EOFException e) {
     if (LOGS_ENABLED) Log.e(TAG, "Exception while reading from 'MTDT' box", e);
     return false;
   } catch (IOException e) {
     if (LOGS_ENABLED) Log.e(TAG, "Exception while reading from 'MTDT' box", e);
     return false;
   }
   return true;
 }
  /**
   * 用本函数代替{@link #setText(CharSequence)}
   *
   * @param cs
   */
  public void setMText(CharSequence cs) {
    text = cs;

    obList.clear();
    //	contentList.clear();

    ArrayList<IS> isList = new ArrayList<MTextView.IS>();
    useDefault = false;
    if (cs instanceof SpannableString) {
      SpannableString ss = (SpannableString) cs;
      ImageSpan[] imageSpans = ss.getSpans(0, ss.length(), ImageSpan.class);
      for (int i = 0; i < imageSpans.length; i++) {
        int s = ss.getSpanStart(imageSpans[i]);
        int e = ss.getSpanEnd(imageSpans[i]);
        IS iS = new IS();
        iS.is = imageSpans[i];
        iS.start = s;
        iS.end = e;
        isList.add(iS);
      }
    }

    String str = cs.toString();

    for (int i = 0, j = 0; i < cs.length(); ) {
      if (j < isList.size()) {
        IS is = isList.get(j);
        if (i < is.start) {
          Integer cp = str.codePointAt(i);
          // 支持增补字符
          if (Character.isSupplementaryCodePoint(cp)) {
            i += 2;
          } else {
            i++;
          }

          obList.add(new String(Character.toChars(cp)));

        } else if (i >= is.start) {
          obList.add(is.is);
          j++;
          i = is.end;
        }
      } else {
        Integer cp = str.codePointAt(i);
        if (Character.isSupplementaryCodePoint(cp)) {
          i += 2;
        } else {
          i++;
        }

        obList.add(new String(Character.toChars(cp)));
      }
    }

    requestLayout();
  }
 @Test
 public void testTerminatingCharProgession() {
   SuffixTreeNaive t = new SuffixTreeNaive();
   t.addString("one");
   String expected = new String(Character.toChars(0x7b));
   assertEquals(expected, t.terminatingChars.get(t.terminatingChars.size() - 1));
   t.addString("two");
   expected = new String(Character.toChars(0x7c));
   assertEquals(expected, t.terminatingChars.get(t.terminatingChars.size() - 1));
 }
Example #4
0
 /**
  * Returns an alphanumeric literal representation of the given number using UTF Superscript Latin
  * Small Letter characters.
  *
  * @param number to convert
  * @return alphanumeric literal representation
  * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and
  *     larger than 9)
  */
 public static final String toSuperscript(int number) {
   if (number < 1 || number > 9) {
     throw new NotImplementedException(
         "Arabic literals - UTF Superscript Latin Small Letter - supported 0<number<10 - number was: "
             + number);
   }
   if (number == 1 || number > 3) {
     // 1, 4-10
     return new String(Character.toChars(number + 8304));
   } else {
     // 2, 3
     return new String(Character.toChars(number + 176));
   }
 }
  private String decodeFileName(String name) {
    String fileName = null;

    try {
      if (getRequest().getParameter("_richfaces_send_http_error") != null) {
        fileName = new String(name.getBytes(encoding), "UTF-8");
      } else {
        StringBuffer buffer = new StringBuffer();
        String[] codes = name.split(";");
        if (codes != null) {
          for (String code : codes) {
            if (code.startsWith("&")) {
              String sCode = code.replaceAll("[&#]*", "");
              Integer iCode = Integer.parseInt(sCode);
              buffer.append(Character.toChars(iCode));
            } else {
              buffer.append(code);
            }
          }
          fileName = buffer.toString();
        }
      }
    } catch (Exception e) {
      fileName = name;
    }

    return fileName;
  }
Example #6
0
 /**
  * Remove invalid XML characters from the string
  *
  * @param text The string containing xml message.
  * @return
  */
 private static String removeNonXMLCharacters(String text) {
   StringBuilder out = new StringBuilder();
   StringBuilder errorMessage = null;
   int codePoint;
   int index = 0;
   while (index < text.length()) {
     codePoint = text.codePointAt(index);
     if ((codePoint == 0x9)
         || (codePoint == 0xA)
         || (codePoint == 0xD)
         || ((codePoint >= 0x20) && (codePoint <= 0xD7FF))
         || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD))
         || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) {
       out.append(Character.toChars(codePoint));
     } else {
       if (errorMessage == null) {
         errorMessage = new StringBuilder();
         errorMessage.append(
             "The message from xdebug contains invalid XML characters: "); // NOI18N
       } else {
         errorMessage.append(", "); // NOI18N
       }
       errorMessage.append(codePoint);
     }
     index += Character.charCount(codePoint);
   }
   if (errorMessage != null) {
     errorMessage.append(
         "\nPlease mentioned it in http://netbeans.org/bugzilla/show_bug.cgi?id=179309."); // NOI18N
     LOGGER.warning(errorMessage.toString());
   }
   return out.toString();
 }
Example #7
0
 @Test
 public void selectSupplementaryCharacter() {
   String s = new String(Character.toChars(135361));
   Document doc = Jsoup.parse("<div k" + s + "='" + s + "'>^" + s + "$/div>");
   assertEquals("div", doc.select("div[k" + s + "]").first().tagName());
   assertEquals("div", doc.select("div:containsOwn(" + s + ")").first().tagName());
 }
Example #8
0
 @Override
 public void reset(EvolutionState state, int thread) {
   for (int x = 0; x < genome.length; x++) {
     int what2generate = state.random[thread].nextInt(1 + intOfZ - intOfA) + intOfA;
     genome[x] = Character.toChars(what2generate)[0];
   }
 }
Example #9
0
  public static List<PatternStringTuple> getUnicodePatterns() throws IOException {
    List<PatternStringTuple> tupleList = new ArrayList<>();
    BufferedReader reader =
        new BufferedReader(
            new InputStreamReader(
                TwitterTokenizer.class.getClassLoader().getResourceAsStream("unicode.csv")));
    String line;
    String[] toks;
    char[] pair;
    String regexp;
    while ((line = reader.readLine()) != null) {
      toks = line.split(",");
      if (toks[0].length() > 4) {
        pair = Character.toChars(Integer.decode("0x" + toks[0]));
        regexp = "(" + pair[0] + pair[1] + ")";
        tupleList.add(new PatternStringTuple(Pattern.compile(regexp), toks[1]));
      }
      regexp = "(\\u" + toks[0] + ")";
      tupleList.add(new PatternStringTuple(Pattern.compile(regexp), toks[1]));
    }

    reader.close();

    return tupleList;
  }
Example #10
0
 private int getGlyphCode(Font font, int codePoint) {
   char[] chars = Character.toChars(codePoint);
   GlyphVector vector =
       font.layoutGlyphVector(
           GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
   return vector.getGlyphCode(0);
 }
  public static void main(String[] args) throws IOException {

    // File           f  = new File(args[0]);
    //   BufferedReader br = new BufferedReader(new FileReader(f));

    BufferedReader br = new BufferedReader((new InputStreamReader(System.in)));

    String line;

    int[] digits;
    String columnName;
    int tmp;
    char c;
    while ((line = br.readLine()) != null) {

      tmp = Integer.parseInt(line);

      digits = convertBase(tmp, 26);

      columnName = "";

      for (int i = 0; i < digits.length; i++) {
        tmp = digits[i];

        if (tmp == -1) break;

        c = Character.toChars(tmp + 65)[0];

        columnName = c + columnName;
      }

      System.out.println(columnName);
    }
  }
Example #12
0
 private static String bt2Str(byte[] arr, int start, int end) {
   StringBuffer buff = new StringBuffer();
   for (int i = start; i < arr.length && i < end; i++) {
     buff.append(String.valueOf(Character.toChars((arr[i] + 256) % 256)));
   }
   return buff.toString();
 }
Example #13
0
 /**
  * This method ensures that the output String has only valid XML unicode characters as specified
  * by the XML 1.0 standard. For reference, please see the standard. This method will return an
  * empty String if the input is null or empty.
  *
  * @author Donoiu Cristian, GPL The String whose non-valid characters we want to remove. in
  *     String, stripped of non-valid characters.
  */
 public static String removeInvalidXMLCharacters(String s) {
   StringBuilder out = new StringBuilder(); // Used to hold the output.
   int codePoint; // Used to reference the current character.
   // String ss = "\ud801\udc00";                           // This is actualy one unicode
   // character, represented by two code units!!!.
   // System.out.println(ss.codePointCount(0, ss.length()));// See: 1
   int i = 0;
   while (i < s.length()) {
     // System.out.println("i=" + i);
     codePoint = s.codePointAt(i); // This is the unicode code of the character.
     if ((codePoint == 0x9)
         || // Consider testing larger ranges first to improve speed.
         (codePoint == 0xA)
         || (codePoint == 0xD)
         || ((codePoint >= 0x20) && (codePoint <= 0xD7FF))
         || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD))
         || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) {
       out.append(Character.toChars(codePoint));
     }
     i +=
         Character.charCount(
             codePoint); // Increment with the number of code units(java chars) needed to represent
                         // a Unicode char.
   }
   return out.toString();
 }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   overridePendingTransition(R.anim.left_in, R.anim.left_out);
   int screenSize =
       getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
   if (screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE
       || screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
   } else {
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
   }
   setContentView(R.layout.activity_main);
   if (savedInstanceState == null) {
     loadSecondActivity();
   }
   TextView tvEmoji = (TextView) findViewById(R.id.tvEmoji);
   int emoji = getResources().getInteger(R.integer.txt_emoji2);
   tvEmoji.setText(new String(Character.toChars(emoji)));
   SharedPreferences shared = getSharedPreferences("SharedKey", MODE_PRIVATE);
   SharedPreferences.Editor editor = shared.edit();
   editor.clear();
   editor.remove("modeKey");
   editor.commit();
 }
Example #15
0
 // http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
 private String buildString(int codePoint) {
   if (Character.charCount(codePoint) == 1) {
     return String.valueOf((char) codePoint);
   } else {
     return new String(Character.toChars(codePoint));
   }
 }
Example #16
0
  public static String firstNonRepeatedMoreEffect(String str) {
    HashMap<Integer, Object> charHash = new HashMap<Integer, Object>();
    Object seenOnce = new Object();
    Object seenMultiple = new Object();
    Object seen;
    final int length = str.length();

    for (int i = 0; i < length; ) {
      int cp = str.codePointAt(i);
      i += Character.charCount(cp);
      seen = charHash.get(cp);
      if (seen == null) {
        charHash.put(cp, seenOnce);
      } else {
        if (seen == seenOnce) {
          charHash.put(cp, seenMultiple);
        }
      }
    }

    for (int i = 0; i < length; ) {
      int cp = str.codePointAt(i);
      i += Character.charCount(cp);
      if (charHash.get(cp) == seenOnce) {
        return new String(Character.toChars(cp));
      }
    }

    return null;
  }
Example #17
0
  /**
   * Replaces characters using the given conversion method.
   *
   * @param conversionMethod The conversion method to be used
   * @param input The input text
   * @param fromCharacter From index
   * @param toCharacter To index
   * @param wrap Characters to put around the converted text
   * @return The converted text
   */
  public static String replaceCharacters(
      final ConversionMethod conversionMethod,
      final String input,
      final int fromCharacter,
      final int toCharacter,
      final String wrap) {
    String convertedText = input;

    for (int i = fromCharacter; i <= toCharacter; i++) {
      final String characterToReplace = new String(Character.toChars(i));

      if (wrap != null) {
        convertedText =
            convertedText.replace(
                characterToReplace,
                wrap + convertText(conversionMethod, characterToReplace) + wrap);
      } else {
        convertedText =
            convertedText.replace(
                characterToReplace, convertText(conversionMethod, characterToReplace));
      }
    }

    return convertedText;
  }
  /** Convert XML char refs to chars and convert "<nowiki></nowiki>" to an empty tag. */
  private String polishRawResult(String raw) {
    StringBuilder b = new StringBuilder();

    int copyFrom = 0;
    int searchFrom = 0;
    int i;
    while ((i = raw.indexOf("&#x", searchFrom)) != -1) {
      searchFrom = i + 3;
      int j = raw.indexOf(';', searchFrom);
      if (j == -1 || j > i + 12) continue;

      int ch = Integer.valueOf(raw.substring(i + 3, j), 0x10);
      switch (ch) {
        case 0x7B: // {
        case 0x7D: // }
        case 0x7C: // |
        case 0x3D: // =
          break;
        default:
          continue;
      }
      b.append(raw.substring(copyFrom, i));
      b.append(Character.toChars(ch));

      searchFrom = copyFrom = j + 1;
    }
    b.append(raw.substring(copyFrom, raw.length()));

    return b.toString().replace("<nowiki></nowiki>", "<nowiki />");
  }
Example #19
0
 static {
   if (tokens.isEmpty()) {
     String token;
     // Tokens by HTML(Decimal) code.
     for (int t = Character.MIN_CODE_POINT; t < Character.MAX_CODE_POINT; t++) {
       if (t < CHAR_CODES[0] && t > CHAR_CODES[1]
           || t < CHAR_CODES[2] && t > CHAR_CODES[3]
           || t < CHAR_CODES[4] && t > CHAR_CODES[5]
           || t < CHAR_CODES[6] && t > CHAR_CODES[7]) {
         token = new StringBuilder(AMP_NUMBER).append(t).append(SEMICOLON).toString();
         tokens.add(token);
         charcodes.put(token, String.valueOf(Character.toChars(t)[0]));
       }
     }
     // Tokens by Entity code.
     tokens.add(LESS_THAN);
     charcodes.put(LESS_THAN, "<");
     tokens.add(GREATER_THAN);
     charcodes.put(GREATER_THAN, ">");
     tokens.add(QUOT);
     charcodes.put(QUOT, "\"");
     tokens.add(AMP_SPACE);
     charcodes.put(AMP_SPACE, SPACE);
     tokens.add(AMP_HEX);
     charcodes.put(AMP_HEX, "&");
     tokens.add(AMP);
     charcodes.put(AMP, "&");
   }
 }
Example #20
0
 /**
  * Returns an alphanumeric literal representation of the given number using UTF Fullwidth
  * characters.
  *
  * @param number to convert
  * @return alphanumeric literal representation
  * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and
  *     larger than 9)
  */
 public static final String toFullwidth(int number) {
   if (number < 1 || number > 9) {
     throw new NotImplementedException(
         "Arabic literals - UTF Fullwidth - supported 0<number<10 - number was: " + number);
   }
   return new String(Character.toChars(number + 65296));
 }
Example #21
0
 @Test
 public void testWithSupplementaryCharacterInAttributeKeyAndValue() {
   String s = new String(Character.toChars(135361));
   Attribute attr = new Attribute(s, "A" + s + "B");
   assertEquals(s + "=\"A" + s + "B\"", attr.html());
   assertEquals(attr.html(), attr.toString());
 }
Example #22
0
 /**
  * Returns an alphanumeric literal representation of the given number using UTF Full Stop
  * characters.
  *
  * @param number to convert
  * @return alphanumeric literal representation
  * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and
  *     larger than 20)
  */
 public static final String toFullStop(int number) {
   if (number < 1 || number > 20) {
     throw new NotImplementedException(
         "Arabic literals - UTF Full Stop - supported 0<number<21 - number was: " + number);
   }
   return new String(Character.toChars(number + 9351));
 }
Example #23
0
 /**
  * Returns an alphanumeric literal representation of the given number using UTF Subscript
  * characters.
  *
  * @param number to convert
  * @return alphanumeric literal representation
  * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and
  *     larger than 9)
  */
 public static final String toSubscript(int number) {
   if (number < 1 || number > 9) {
     throw new NotImplementedException(
         "Arabic literals - UTF Subscript - supported 0<number<10 - number was: " + number);
   }
   return new String(Character.toChars(number + 8320));
 }
 private static String convertUnicode(String emo) {
   emo = emo.substring(1, emo.length() - 1);
   if (emo.length() < 6) {
     return new String(Character.toChars(Integer.parseInt(emo, 16)));
   }
   String[] emos = emo.split("_");
   char[] char0 = Character.toChars(Integer.parseInt(emos[0], 16));
   char[] char1 = Character.toChars(Integer.parseInt(emos[1], 16));
   char[] emoji = new char[char0.length + char1.length];
   for (int i = 0; i < char0.length; i++) {
     emoji[i] = char0[i];
   }
   for (int i = char0.length; i < emoji.length; i++) {
     emoji[i] = char1[i - char0.length];
   }
   return new String(emoji);
 }
Example #25
0
 /**
  * Reads and buffers all characters that qualify as credit card characters. Returns the first
  * character that no longer qualifies as a credit card character.
  */
 private int bufferCardCharacters(int c) throws IOException {
   if (isCardChar(c))
     do {
       sb.append(Character.toChars(c));
       c = in.read();
     } while (isCardChar(c));
   return c;
 }
Example #26
0
 /**
  * Returns an alphanumeric literal representation of the given number using UTF Dingbat Negative
  * Circled Digit characters.
  *
  * @param number to convert
  * @return alphanumeric literal representation
  * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and
  *     larger than 10)
  */
 public static final String toDingbatNegativeCircledDigit(int number) {
   if (number < 1 || number > 10) {
     throw new NotImplementedException(
         "Arabic literals - UTF Dingbat Negative Circled - supported 0<number<11 - number was: "
             + number);
   }
   return new String(Character.toChars(number + 10101));
 }
Example #27
0
 /**
  * Returns an alphanumeric literal representation of the given number using UTF Double Circled
  * Digit/Number characters.
  *
  * @param number to convert
  * @return alphanumeric literal representation
  * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and
  *     larger than 10)
  */
 public static final String toDoubleCircledDigit(int number) {
   if (number < 1 || number > 20) {
     throw new NotImplementedException(
         "Arabic literals - UTF Double Circled Digit/Number - supported 0<number<10 - number was: "
             + number);
   }
   return new String(Character.toChars(number + 9460));
 }
Example #28
0
 /**
  * Returns an alphanumeric literal representation of the given number using UTF Parenthesized
  * Digit/Number characters.
  *
  * @param number to convert
  * @return alphanumeric literal representation
  * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and
  *     larger than 20)
  */
 public static final String toParenthesized(int number) {
   if (number < 1 || number > 20) {
     throw new NotImplementedException(
         "Arabic literals - UTF Parenthesized Digit/Number - supported 0<number<21 - number was: "
             + number);
   }
   return new String(Character.toChars(number + 9331));
 }
  private PasswordStrengthClass(int length, PasswordCharacterRange.CharacterBlock... blocks) {
    StringBuffer basePassword = new StringBuffer();

    char[] initialChars =
        Character.toChars(blocks[0].getRanges().iterator().next().getLowerBound());
    for (int i = 0; i < ((length - blocks.length) + 1); i++) {
      basePassword.append(initialChars);
    }

    for (int i = 1; i < blocks.length; i++) {
      char[] nextChars = Character.toChars(blocks[i].getRanges().iterator().next().getLowerBound());
      basePassword.append(nextChars);
    }

    PasswordStrengthMeter passwordStrengthMeter = PasswordStrengthMeter.getInstance();
    this.iterationCount = passwordStrengthMeter.iterationCount(basePassword.toString());
  }
  @Override
  public final boolean incrementToken() throws IOException {
    this.clearAttributes();
    int length = 0;
    int start = -1;
    int end = -1;
    char[] buffer = this.termAtt.buffer();

    while (true) {
      if (this.bufferIndex >= this.dataLen) {
        this.offset += this.dataLen;
        this.charUtils.fill(this.ioBuffer, this.input);
        if (this.ioBuffer.getLength() == 0) {
          this.dataLen = 0;
          if (length <= 0) {
            this.finalOffset = this.correctOffset(this.offset);
            return false;
          }
          break;
        }

        this.dataLen = this.ioBuffer.getLength();
        this.bufferIndex = 0;
      }

      int c =
          this.charUtils.codePointAt(
              this.ioBuffer.getBuffer(), this.bufferIndex, this.ioBuffer.getLength());
      int charCount = Character.charCount(c);
      this.bufferIndex += charCount;
      if (this.isTokenChar(c)) {
        if (length == 0) {
          assert start == -1;

          start = this.offset + this.bufferIndex - charCount;
          end = start;
        } else if (length >= buffer.length - 1) {
          buffer = this.termAtt.resizeBuffer(2 + length);
        }

        end += charCount;
        length += Character.toChars(this.normalize(c), buffer, length);
        if (length >= MAX_WORD_LEN) {
          break;
        }
      } else if (length > 0) {
        break;
      }
    }

    this.termAtt.setLength(length);

    assert start != -1;

    this.offsetAtt.setOffset(this.correctOffset(start), this.finalOffset = this.correctOffset(end));
    return true;
  }