我如何以编程方式确定特定字符集中字符的最大大小(以字节为单位)? [英] How can I programatically determine the maximum size in bytes of a character in a specific charset?

查看:106
本文介绍了我如何以编程方式确定特定字符集中字符的最大大小(以字节为单位)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到所有支持的字符集通过使用:

  Object [] Charsets = Charset.availableCharsets .toArray(); 



现在我需要遍历每个可以在该字符集中编码的字符。为此,我考虑使用每个编码的最大字节数,并通过 Byte.MIN_VALUE Byte.MAX_VALUE 为每个字节。然后,该字节数组通过接受 byte [] 数组和特定编码的 String 构造函数。 / p>

然而,我找不到任何关于如何确定特定字符集中字符表示形式的最大长度(以字节为单位)的线索。



我尝试使用空格字符(即)在该编码中创建一个字符串,并使用 .getBytes(< specific charset& ).length 。但我相信这只适用于固定大小的字符集。有一些字符集,其中字符的编码可以有可变的字节数。



这不是一个商业软件,所以它不需要一个漂亮的解决方案。我需要创建一种视觉地图的每个支持的字符集。每个字符表示被写入图像。我也不确定我应该如何选择一个字体,可以正确显示字符集的所有字符。



任何想法?

解决方案

  charset.newEncoder()。maxBytesPerChar()


I am getting all supported charsets by using :

Object[] Charsets = Charset.availableCharsets().keySet().toArray();

I now need to iterate through each character that can be encoded in that charset. To do this I thought about using the maximum number of bytes for each encoding and going through Byte.MIN_VALUE to Byte.MAX_VALUE for each byte. That byte array I then pass it through the String constructor that accepts a byte[] array and a specific encoding.

However can't find any clues on how I can determine the maximum length in bytes of a character representation in a specific charset.

I tried using the space character (i.e. " ") to create a string in that encoding and using .getBytes("<specific charset>").length. However I believe this only works for fixed size charsets. There are charsets in which the encoding of a character can have a variable number of bytes.

This is not a commercial software so it does not need a pretty solution. I need to create a sort of visual map of each supported charset. Each character representation is written into an image. I am also not sure on how I should select a font that can properly display all characters of a charset.

Any thoughts?

解决方案

charset.newEncoder().maxBytesPerChar()

这篇关于我如何以编程方式确定特定字符集中字符的最大大小(以字节为单位)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆