当前位置: 首页>>代码示例>>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;未经允许,请勿转载。