示例#1
0
 @Override
 public final synchronized String toString() {
   final TokenBuilder tb = new TokenBuilder();
   for (final Entry<String, Object> e : props.entrySet()) {
     if (!tb.isEmpty()) tb.add(',');
     tb.add(e.getKey()).add('=').addExt(e.getValue());
   }
   return tb.toString();
 }
示例#2
0
  /**
   * Converts to HANKAKU characters.
   *
   * @param text Japanese text
   * @return result of conversion(->HANKAKU)
   */
  private static byte[] toHankaku(final byte[] text) {
    if (ascii(text)) return text;

    final int tl = text.length;
    final TokenBuilder tb = new TokenBuilder(tl);
    for (int t = 0; t < tl; t += cl(text, t)) {
      final int c = cp(text, t);
      if (c >= 0xFF10 && c <= 0xFF19 || c >= 0xFF21 && c <= 0xFF3A || c >= 0xFF41 && c <= 0xFF5A) {
        tb.add(c - 0xFEE0);
      } else if (c == 0x3000) { // IDEOGRAPHIC SPACE
        tb.add(0x0020);
      } else if (c == 0xFF01) { // !
        tb.add(0x0021);
      } else if (c == 0xFF02) { // " FULLWIDTH QUOTATION MARK
        tb.add(0x0022);
      } else if (c == 0x201C) { // " LEFT DOUBLE QUOTATION MARK
        tb.add(0x0022);
      } else if (c == 0x201D) { // " RIGHT DOUBLE QUOTATION MARK
        tb.add(0x0022);
      } else if (c == 0xFF03) { // #
        tb.add(0x0023);
      } else if (c == 0xFF04) { // $
        tb.add(0x0024);
      } else if (c == 0xFF05) { // %
        tb.add(0x0025);
      } else if (c == 0xFF06) { // &
        tb.add(0x0026);
      } else if (c == 0xFF07) { // ' FULLWIDTH APOSTROPHE
        tb.add(0x0027);
      } else if (c == 0x2018) { // ' LEFT SINGLE QUOTATION MARK
        tb.add(0x0027);
      } else if (c == 0x2019) { // ' RIGHT SINGLE QUOTATION MARK
        tb.add(0x0027);
      } else if (c == 0xFF08) { // (
        tb.add(0x0028);
      } else if (c == 0xFF09) { // )
        tb.add(0x0029);
      } else if (c == 0xFF0A) { // *
        tb.add(0x002A);
      } else if (c == 0xFF0B) { // +
        tb.add(0x002B);
      } else if (c == 0xFF0C) { // ,
        tb.add(0x002C);
      } else if (c == 0xFF0D) { // -
        tb.add(0x002D);
      } else if (c == 0xFF0E) { // .
        tb.add(0x002E);
      } else if (c == 0xFF0F) { // /
        tb.add(0x002F);
      } else if (c == 0xFF1A) { // :
        tb.add(0x003A);
      } else if (c == 0xFF1B) { // ;
        tb.add(0x003B);
      } else if (c == 0xFF1C) { // <
        tb.add(0x003C);
      } else if (c == 0xFF1D) { // =
        tb.add(0x003D);
      } else if (c == 0xFF1E) { // >
        tb.add(0x003E);
      } else if (c == 0xFF1F) { // ?
        tb.add(0x003F);
      } else if (c == 0xFF20) { // @
        tb.add(0x0040);
      } else if (c == 0xFF3B) { // [
        tb.add(0x005B);
      } else if (c == 0xFFE5) { // \
        tb.add(0x005C);
      } else if (c == 0xFF3D) { // ]
        tb.add(0x005D);
      } else if (c == 0xFF3E) { // ^
        tb.add(0x005E);
      } else if (c == 0xFF3F) { // _
        tb.add(0x005F);
      } else if (c == 0xFF40) { // `
        tb.add(0x0060);
      } else if (c == 0xFF5B) { // {
        tb.add(0x007B);
      } else if (c == 0xFF5C) { // |
        tb.add(0x007C);
      } else if (c == 0xFF5D) { // }
        tb.add(0x007D);
      } else if (c == 0xFF5E) { // ~
        tb.add(0x007E);
      } else {
        tb.add(c);
      }
    }
    return tb.finish();
  }
示例#3
0
  /**
   * Reads the configuration file and initializes the project properties. The file is located in the
   * project home directory.
   *
   * @param prop property file extension
   */
  protected synchronized void read(final String prop) {
    file = new IOFile(HOME + IO.BASEXSUFFIX + prop);

    final StringList read = new StringList();
    final TokenBuilder err = new TokenBuilder();
    if (!file.exists()) {
      err.addExt("Saving properties in \"%\"..." + NL, file);
    } else {
      BufferedReader br = null;
      try {
        br = new BufferedReader(new FileReader(file.file()));
        for (String line; (line = br.readLine()) != null; ) {
          line = line.trim();
          if (line.isEmpty() || line.charAt(0) == '#') continue;
          final int d = line.indexOf('=');
          if (d < 0) {
            err.addExt("%: \"%\" ignored. " + NL, file, line);
            continue;
          }

          final String val = line.substring(d + 1).trim();
          String key = line.substring(0, d).trim();

          // extract numeric value in key
          int num = 0;
          final int ss = key.length();
          for (int s = 0; s < ss; ++s) {
            if (Character.isDigit(key.charAt(s))) {
              num = Integer.parseInt(key.substring(s));
              key = key.substring(0, s);
              break;
            }
          }
          read.add(key);

          final Object entry = props.get(key);
          if (entry == null) {
            err.addExt("%: \"%\" not found. " + NL, file, key);
          } else if (entry instanceof String) {
            props.put(key, val);
          } else if (entry instanceof Integer) {
            props.put(key, Integer.parseInt(val));
          } else if (entry instanceof Boolean) {
            props.put(key, Boolean.parseBoolean(val));
          } else if (entry instanceof String[]) {
            if (num == 0) {
              props.put(key, new String[Integer.parseInt(val)]);
            } else {
              ((String[]) entry)[num - 1] = val;
            }
          } else if (entry instanceof int[]) {
            ((int[]) entry)[num] = Integer.parseInt(val);
          }
        }
      } catch (final Exception ex) {
        err.addExt("% could not be parsed." + NL, file);
        Util.debug(ex);
      } finally {
        if (br != null)
          try {
            br.close();
          } catch (final IOException ex) {
          }
      }
    }

    // check if all mandatory files have been read
    try {
      if (err.isEmpty()) {
        boolean ok = true;
        for (final Field f : getClass().getFields()) {
          final Object obj = f.get(null);
          if (!(obj instanceof Object[])) continue;
          final String key = ((Object[]) obj)[0].toString();
          ok &= read.contains(key);
        }
        if (!ok) err.addExt("Saving properties in \"%\"..." + NL, file);
      }
    } catch (final IllegalAccessException ex) {
      Util.notexpected(ex);
    }

    if (!err.isEmpty()) {
      Util.err(err.toString());
      write();
    }
  }