當前位置: 首頁>>代碼示例>>Java>>正文


Java Form類代碼示例

本文整理匯總了Java中java.text.Normalizer.Form的典型用法代碼示例。如果您正苦於以下問題:Java Form類的具體用法?Java Form怎麽用?Java Form使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Form類屬於java.text.Normalizer包,在下文中一共展示了Form類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode_UTF8

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * Encodes a string containing non ASCII characters using an UTF-8 encoder.
 * 
 * @param s
 *            The string the encode (assuming ASCII characters only)
 * @param e
 *            A character that does not require encoding if found in the
 *            string.
 */
private static String encode_UTF8(String s, char e) {
	// TODO: Normalizer requires Java 6!
	String n = (Normalizer.isNormalized(s, Form.NFKC)) ? s : Normalizer.normalize(s, Form.NFKC);
	// convert String to UTF-8
	ByteBuffer bb = UTF8.encode(n);
	// URI encode
	StringBuffer sb = new StringBuffer();

	while (bb.hasRemaining()) {
		int b = bb.get() & 0xff;

		if (isUnreserved(b) || b == e) {
			sb.append((char) b);
		} else {
			appendEscape(sb, (byte) b);
		}
	}
	return sb.toString();
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:29,代碼來源:URICoder.java

示例2: minimalEncode_UTF8

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * Encodes a string containing non ASCII characters using an UTF-8 encoder.
 * 
 * @param s
 *            The string the encode (assuming ASCII characters only)
 */
private static String minimalEncode_UTF8(String s) {
	// TODO: Normalizer requires Java 6!
	String n = (Normalizer.isNormalized(s, Form.NFKC)) ? s : Normalizer.normalize(s, Form.NFKC);
	// convert String to UTF-8
	ByteBuffer bb = UTF8.encode(n);
	// URI encode
	StringBuffer sb = new StringBuffer();

	while (bb.hasRemaining()) {
		int b = bb.get() & 0xff;

		if (isLegal(b)) {
			sb.append((char) b);
		} else {
			appendEscape(sb, (byte) b);
		}
	}
	return sb.toString();
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:26,代碼來源:URICoder.java

示例3: translateBytes

import java.text.Normalizer.Form; //導入依賴的package包/類
@Override
public Object translateBytes(byte[] bytes, DataFlavor flavor,
                                long format, Transferable transferable) throws IOException {

        if (format == CF_URL && URL.class.equals(flavor.getRepresentationClass()))
        {
            String charset = getDefaultTextCharset();
            if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
                try {
                    charset = new String((byte[])transferable.getTransferData(javaTextEncodingFlavor), "UTF-8");
                } catch (UnsupportedFlavorException cannotHappen) {
                }
            }

            return new URL(new String(bytes, charset));
        }

        if (format == CF_STRING) {
            bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8");
        }

        return super.translateBytes(bytes, flavor, format, transferable);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:CDataTransferer.java

示例4: removeDiacritics

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * Remove diacritics from the specified string.
 * @param s
 * @return a copy of the specified string with diacritics removed.
 */
public static final String removeDiacritics(String s) {
	String n = Normalizer.normalize(s, Form.NFD);
	StringBuilder sb = null;
	for (int i = 0; i < n.length(); ++i) {
		char c = n.charAt(i);
		UnicodeBlock b = UnicodeBlock.of(c);
		if (UnicodeBlock.COMBINING_DIACRITICAL_MARKS.equals(b) || UnicodeBlock.COMBINING_DIACRITICAL_MARKS_SUPPLEMENT.equals(b)) {
			if (sb == null) {
				sb = new StringBuilder(n.length());
				sb.append(n.substring(0, i));
			}
			continue;
		}
		if (sb != null)
			sb.append(c);
	}
	if (sb == null)
		return n;
	return sb.toString();
}
 
開發者ID:Bibliome,項目名稱:bibliome-java-utils,代碼行數:26,代碼來源:Strings.java

示例5: getHash

import java.text.Normalizer.Form; //導入依賴的package包/類
private static String getHash(int iterations, byte[] salt, String text, String algorithm)
    throws NoSuchAlgorithmException {
    MessageDigest digest;
    if (--iterations < 0) {
        iterations = 0;
    }
    byte[] data;
    try {
        digest = MessageDigest.getInstance(algorithm);
        text = Normalizer.normalize(text, Form.NFC);
        if (salt != null) {
            digest.update(salt);
        }
        data = digest.digest(text.getBytes("UTF-8"));
        for (int i = 0; i < iterations; i++) {
            data = digest.digest(data);
        }
    } catch (UnsupportedEncodingException e) {
        throw new MCRException("Could not get " + algorithm + " checksum", e);
    }
    return toHexString(data);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:23,代碼來源:MCRUtils.java

示例6: toString

import java.text.Normalizer.Form; //導入依賴的package包/類
String toString(List<List<TextPosition>> words)
{
    StringBuilder stringBuilder = new StringBuilder();
    boolean first = true;
    for (List<TextPosition> word : words)
    {
        if (first)
            first = false;
        else
            stringBuilder.append(' ');
        for (TextPosition textPosition : word)
        {
            stringBuilder.append(textPosition.getUnicode());
        }
    }
    // cf. http://stackoverflow.com/a/7171932/1729265
    return Normalizer.normalize(stringBuilder, Form.NFKC);
}
 
開發者ID:mkl-public,項目名稱:testarea-pdfbox2,代碼行數:19,代碼來源:TextSection.java

示例7: getHash

import java.text.Normalizer.Form; //導入依賴的package包/類
private static String getHash(int iterations, byte[] salt, String str, String algorithm)
    throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest digest;
    int it = iterations;
    if (--it < 0) {
        it = 0;
    }
    byte[] data;

    digest = MessageDigest.getInstance(algorithm);
    String text = Normalizer.normalize(str, Form.NFC);
    if (salt != null) {
        digest.update(salt);
    }
    data = digest.digest(text.getBytes("UTF-8"));
    for (int i = 0; i < it; i++) {
        data = digest.digest(data);
    }

    return Hash.toHexString(data);
}
 
開發者ID:MyCoRe-Org,項目名稱:MyVidCoRe,代碼行數:22,代碼來源:Hash.java

示例8: hashIt

import java.text.Normalizer.Form; //導入依賴的package包/類
public static String hashIt ( final String salt, String data )
{
    data = Normalizer.normalize ( data, Form.NFC );

    final byte[] strData = data.getBytes ( StandardCharsets.UTF_8 );
    final byte[] saltData = salt.getBytes ( StandardCharsets.UTF_8 );

    final byte[] first = new byte[saltData.length + strData.length];
    System.arraycopy ( saltData, 0, first, 0, saltData.length );
    System.arraycopy ( strData, 0, first, saltData.length, strData.length );

    final MessageDigest md = createDigest ();

    byte[] digest = md.digest ( first );
    final byte[] current = new byte[saltData.length + digest.length];

    for ( int i = 0; i < 1000; i++ )
    {
        System.arraycopy ( saltData, 0, current, 0, saltData.length );
        System.arraycopy ( digest, 0, current, saltData.length, digest.length );

        digest = md.digest ( current );
    }

    return Base64.getEncoder ().encodeToString ( digest );
}
 
開發者ID:eclipse,項目名稱:packagedrone,代碼行數:27,代碼來源:Users.java

示例9: expanded

import java.text.Normalizer.Form; //導入依賴的package包/類
@Override
public Fragment expanded() {
  char[] cs = super.innerText().toCharArray();

  String accent = charMap.get(innerText().substring(0, 1));
  if (accent == null) {
    accent = "\uFFFD";
    Message m = Message.builder("char.accent.unknown")
            .fromNode(this)
            .addNote("Character " + text + " cannot be expanded.")
            .build();
    Log.getInstance().add(m);
  }
  String str = "" + cs[1] + accent;
  str = Normalizer.normalize(str, Form.NFC);
  return wrap("ACCENT", str);
}
 
開發者ID:ubermichael,項目名稱:isetools,代碼行數:18,代碼來源:AccentCharNode.java

示例10: encodeUTF8

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * Encodes a string containing non ASCII characters using an UTF-8 encoder.
 *
 * @param s The string the encode (assuming ASCII characters only)
 * @param e A character that does not require encoding if found in the string.
 */
private static String encodeUTF8(String s, char e) {
  String n = (Normalizer.isNormalized(s, Form.NFKC)) ? s : Normalizer.normalize(s, Form.NFKC);
  // convert String to UTF-8
  ByteBuffer bb = StandardCharsets.UTF_8.encode(n);
  // URI encode
  StringBuilder sb = new StringBuilder();
  while (bb.hasRemaining()) {
    int b = bb.get() & 0xff;
    if (isUnreserved(b) || b == e) {
      sb.append((char) b);
    } else {
      appendEscape(sb, (byte) b);
    }
  }
  return sb.toString();
}
 
開發者ID:pageseeder,項目名稱:berlioz,代碼行數:23,代碼來源:URICoder.java

示例11: minimalEncodeUTF8

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * Encodes a string containing non ASCII characters using an UTF-8 encoder.
 *
 * @param s The string the encode (assuming ASCII characters only)
 */
private static String minimalEncodeUTF8(String s) {
  String n = (Normalizer.isNormalized(s, Form.NFKC)) ? s : Normalizer.normalize(s, Form.NFKC);
  // convert String to UTF-8
  ByteBuffer bb = StandardCharsets.UTF_8.encode(n);
  // URI encode
  StringBuilder sb = new StringBuilder();
  while (bb.hasRemaining()) {
    int b = bb.get() & 0xff;
    if (isLegal(b)) {
      sb.append((char) b);
    } else {
      appendEscape(sb, (byte) b);
    }
  }
  return sb.toString();
}
 
開發者ID:pageseeder,項目名稱:berlioz,代碼行數:22,代碼來源:URICoder.java

示例12: encode_UTF8

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * Encodes a string containing non ASCII characters using an UTF-8 encoder.
 *
 * @param s The string the encode (assuming ASCII characters only)
 * @param e A character that does not require encoding if found in the string.
 */
private static String encode_UTF8(String s, char e) {
  // TODO: Normalizer requires Java 6!
  String n = (Normalizer.isNormalized(s, Form.NFKC)) ? s : Normalizer.normalize(s, Form.NFKC);
  // convert String to UTF-8
  ByteBuffer bb = UTF8.encode(n);
  // URI encode
  StringBuffer sb = new StringBuffer();
  while (bb.hasRemaining()) {
    int b = bb.get() & 0xff;
    if (isUnreserved(b) || b == e) {
      sb.append((char) b);
    } else {
      appendEscape(sb, (byte) b);
    }
  }
  return sb.toString();
}
 
開發者ID:pageseeder,項目名稱:furi,代碼行數:24,代碼來源:URICoder.java

示例13: minimalEncode_UTF8

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * Encodes a string containing non ASCII characters using an UTF-8 encoder.
 *
 * @param s The string the encode (assuming ASCII characters only)
 */
private static String minimalEncode_UTF8(String s) {
  // TODO: Normalizer requires Java 6!
  String n = (Normalizer.isNormalized(s, Form.NFKC)) ? s : Normalizer.normalize(s, Form.NFKC);
  // convert String to UTF-8
  ByteBuffer bb = UTF8.encode(n);
  // URI encode
  StringBuffer sb = new StringBuffer();
  while (bb.hasRemaining()) {
    int b = bb.get() & 0xff;
    if (isLegal(b)) {
      sb.append((char) b);
    } else {
      appendEscape(sb, (byte) b);
    }
  }
  return sb.toString();
}
 
開發者ID:pageseeder,項目名稱:furi,代碼行數:23,代碼來源:URICoder.java

示例14: getSlug

import java.text.Normalizer.Form; //導入依賴的package包/類
/**
 * 獲取字符串的Slug.
 * @param str - 待獲取Slug的字符串
 * @return 字符串對應的Slug
 */
public static String getSlug(String str) {
	if ( str == null ) {
		return "";
	}
	
	// Rid of White Spaces
	String noWhiteSpace = WHITESPACE.matcher(str.trim()).replaceAll("-");
	// Processing Non-ASCII Characters
	try {
		noWhiteSpace = URLEncoder.encode(noWhiteSpace, "UTF-8");
	} catch (UnsupportedEncodingException e) {
		// Never reach here
	}
	// Slugify String
	String normalized = Normalizer.normalize(noWhiteSpace, Form.NFD);
	
	return normalized.toLowerCase();
}
 
開發者ID:hzxie,項目名稱:voj,代碼行數:24,代碼來源:SlugifyUtils.java

示例15: literal

import java.text.Normalizer.Form; //導入依賴的package包/類
@Override
    public void literal(final String name, final String value) {
        //A Subfield has one character or digit exactly.
        if (name.length() != 1) {
            throw new FormatException(name);
        }
        if (!entityOpen) {
            throw new FormatException(name); //new exceptions definition for literal out of entity
        }
        final String valueNew = Normalizer.normalize(value, Form.NFD);
        if (idnControlSubField) {
            // it is a [email protected] field, the same record id delivered with record should follow
            if (!this.id.equals(value)) {
                throw new MissingIdException(value);
            }
            idnControlSubField = false; //only one record Id will be checked.
        }
        builder.append(SUB_DELIMITER);
        builder.append(name);
        builder.append(valueNew);
}
 
開發者ID:metafacture,項目名稱:metafacture-core,代碼行數:22,代碼來源:PicaEncoder.java


注:本文中的java.text.Normalizer.Form類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。