Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
1590e106
提交
1590e106
authored
3月 13, 2020
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删除多余包
上级
103583a8
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
0 行增加
和
180 行删除
+0
-180
CharsetKit.java
...src/main/java/com/ruoyi/common/utils/text/CharsetKit.java
+0
-87
Convert.java
ruoyi/src/main/java/com/ruoyi/common/utils/text/Convert.java
+0
-0
StrFormatter.java
...c/main/java/com/ruoyi/common/utils/text/StrFormatter.java
+0
-93
没有找到文件。
ruoyi/src/main/java/com/ruoyi/common/utils/text/CharsetKit.java
deleted
100644 → 0
浏览文件 @
103583a8
package
com
.
ruoyi
.
common
.
utils
.
text
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
com.ruoyi.common.utils.StringUtils
;
/**
* 字符集工具类
*
* @author ruoyi
*
*/
public
class
CharsetKit
{
/** ISO-8859-1 */
public
static
final
String
ISO_8859_1
=
"ISO-8859-1"
;
/** UTF-8 */
public
static
final
String
UTF_8
=
"UTF-8"
;
/** GBK */
public
static
final
String
GBK
=
"GBK"
;
/** ISO-8859-1 */
public
static
final
Charset
CHARSET_ISO_8859_1
=
Charset
.
forName
(
ISO_8859_1
);
/** UTF-8 */
public
static
final
Charset
CHARSET_UTF_8
=
Charset
.
forName
(
UTF_8
);
/** GBK */
public
static
final
Charset
CHARSET_GBK
=
Charset
.
forName
(
GBK
);
/**
* 转换为Charset对象
*
* @param charset 字符集,为空则返回默认字符集
* @return Charset
*/
public
static
Charset
charset
(
String
charset
)
{
return
StringUtils
.
isEmpty
(
charset
)
?
Charset
.
defaultCharset
()
:
Charset
.
forName
(
charset
);
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public
static
String
convert
(
String
source
,
String
srcCharset
,
String
destCharset
)
{
return
convert
(
source
,
Charset
.
forName
(
srcCharset
),
Charset
.
forName
(
destCharset
));
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public
static
String
convert
(
String
source
,
Charset
srcCharset
,
Charset
destCharset
)
{
if
(
null
==
srcCharset
)
{
srcCharset
=
StandardCharsets
.
ISO_8859_1
;
}
if
(
null
==
destCharset
)
{
srcCharset
=
StandardCharsets
.
UTF_8
;
}
if
(
StringUtils
.
isEmpty
(
source
)
||
srcCharset
.
equals
(
destCharset
))
{
return
source
;
}
return
new
String
(
source
.
getBytes
(
srcCharset
),
destCharset
);
}
/**
* @return 系统字符集编码
*/
public
static
String
systemCharset
()
{
return
Charset
.
defaultCharset
().
name
();
}
}
ruoyi/src/main/java/com/ruoyi/common/utils/text/Convert.java
deleted
100644 → 0
浏览文件 @
103583a8
差异被折叠。
点击展开。
ruoyi/src/main/java/com/ruoyi/common/utils/text/StrFormatter.java
deleted
100644 → 0
浏览文件 @
103583a8
package
com
.
ruoyi
.
common
.
utils
.
text
;
import
com.ruoyi.common.utils.StringUtils
;
/**
* 字符串格式化
*
* @author ruoyi
*/
public
class
StrFormatter
{
public
static
final
String
EMPTY_JSON
=
"{}"
;
public
static
final
char
C_BACKSLASH
=
'\\'
;
public
static
final
char
C_DELIM_START
=
'{'
;
public
static
final
char
C_DELIM_END
=
'}'
;
/**
* 格式化字符串<br>
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
* 例:<br>
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
*
* @param strPattern 字符串模板
* @param argArray 参数列表
* @return 结果
*/
public
static
String
format
(
final
String
strPattern
,
final
Object
...
argArray
)
{
if
(
StringUtils
.
isEmpty
(
strPattern
)
||
StringUtils
.
isEmpty
(
argArray
))
{
return
strPattern
;
}
final
int
strPatternLength
=
strPattern
.
length
();
// 初始化定义好的长度以获得更好的性能
StringBuilder
sbuf
=
new
StringBuilder
(
strPatternLength
+
50
);
int
handledPosition
=
0
;
int
delimIndex
;
// 占位符所在位置
for
(
int
argIndex
=
0
;
argIndex
<
argArray
.
length
;
argIndex
++)
{
delimIndex
=
strPattern
.
indexOf
(
EMPTY_JSON
,
handledPosition
);
if
(
delimIndex
==
-
1
)
{
if
(
handledPosition
==
0
)
{
return
strPattern
;
}
else
{
// 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
sbuf
.
append
(
strPattern
,
handledPosition
,
strPatternLength
);
return
sbuf
.
toString
();
}
}
else
{
if
(
delimIndex
>
0
&&
strPattern
.
charAt
(
delimIndex
-
1
)
==
C_BACKSLASH
)
{
if
(
delimIndex
>
1
&&
strPattern
.
charAt
(
delimIndex
-
2
)
==
C_BACKSLASH
)
{
// 转义符之前还有一个转义符,占位符依旧有效
sbuf
.
append
(
strPattern
,
handledPosition
,
delimIndex
-
1
);
sbuf
.
append
(
Convert
.
utf8Str
(
argArray
[
argIndex
]));
handledPosition
=
delimIndex
+
2
;
}
else
{
// 占位符被转义
argIndex
--;
sbuf
.
append
(
strPattern
,
handledPosition
,
delimIndex
-
1
);
sbuf
.
append
(
C_DELIM_START
);
handledPosition
=
delimIndex
+
1
;
}
}
else
{
// 正常占位符
sbuf
.
append
(
strPattern
,
handledPosition
,
delimIndex
);
sbuf
.
append
(
Convert
.
utf8Str
(
argArray
[
argIndex
]));
handledPosition
=
delimIndex
+
2
;
}
}
}
// append the characters following the last {} pair.
// 加入最后一个占位符后所有的字符
sbuf
.
append
(
strPattern
,
handledPosition
,
strPattern
.
length
());
return
sbuf
.
toString
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论