Skip to content

Commit bb50913

Browse files
committed
Merge remote-tracking branch 'origin/alpha' into alpha
2 parents 88704f4 + 8158750 commit bb50913

30 files changed

+5637
-14
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<a href="https://gitee.com/ForteScarlet/CatCode" target="_blank">gitee</a>
1212
</span> <br />
1313
<small> &gt; 感谢 <a href="https://github.com/ForteScarlet/simpler-robot" target="_blank">simple-robot</a> 开发团队成员制作的猫猫logo &lt; </small> <br />
14+
&gt; 如果有点击一下⭐的话,猫猫会很开心哦~ &lt; <br />
1415
<a href="https://repo1.maven.org/maven2/love/forte/catcode/" target="_blank" >
1516
<img src="https://img.shields.io/maven-central/v/love.forte/catcode" />
1617
</a>
@@ -100,15 +101,19 @@
100101
```
101102

102103
## JS
103-
将会通过kotlin多平台实现,并发布于github release和npm
104+
将会通过kotlin多平台实现,提供js库,并发布于github release\[、Maven和npm(待议)]
105+
106+
抢先预览:[CatCode-multiplatform](https://github.com/ForteScarlet/CatCode-multiplatform)
104107

105108

106109
## Native
107-
将会通过kotlin多平台实现,提供`.h`头文件与对应`.dll`(windows)、`.so`(linux)文件。
110+
将会通过kotlin多平台实现,提供`.h`头文件与对应的`.dll`(windows)、`.so`(linux)文件。
111+
112+
抢先预览:[CatCode-multiplatform](https://github.com/ForteScarlet/CatCode-multiplatform)
108113

109114

110-
## 其他语言
111-
敬请期待...
115+
<br>
116+
<br>
112117

113118
> 你可以基于标准CAT码格式自行实现。
114119
@@ -241,7 +246,7 @@ final Neko alAll = NekoObjects.getNekoAtAll();
241246

242247
#### 3. 通过工具类获取
243248
```java
244-
CatCodeUtil.toCat("at", "qq=123")
249+
final String at = CatCodeUtil.toCat("at", "qq=123");
245250
```
246251

247252

UPDATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
## alpha.3
1010
- 追加 `lazy` (属性值懒加载)相关的neko,以及对应的builder。(`CatCodeUtil#getLazyNekoBuilder`
11+
12+
## alpha.4
13+
- 包路径移动: `love.forte.catcode.*` -> `catcode.*`

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
<scm>
1717
<url>https://github.com/ForteScarlet/CatCode</url>
1818
</scm>
19+
1920
<url>https://github.com/ForteScarlet/CatCode</url>
21+
2022
<description>猫猫码,一个可爱的通用特殊码。/ Cat code, the spirit of CQ code continues, a cute universal special code.
23+
2124
</description>
2225

2326
<properties>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) 2020. ForteScarlet
3+
*
4+
* catCode库相关代码使用 MIT License 开源,请遵守协议相关条款。
5+
*
6+
* about MIT: https://opensource.org/licenses/MIT
7+
*
8+
*
9+
*
10+
*
11+
*/
12+
13+
@file:Suppress("unused")
14+
@file:JvmName("Cats")
15+
package catcode
16+
17+
/*
18+
& -> &amp;
19+
[ -> &#91;
20+
] -> &#93;
21+
*/
22+
/*
23+
& -> &amp;
24+
[ -> &#91;
25+
] -> &#93;
26+
, -> &#44;
27+
*/
28+
29+
internal val CAT_KV_SPLIT_ARRAY: Array<String> = arrayOf(CAT_KV)
30+
internal val CAT_PS_SPLIT_ARRAY: Array<String> = arrayOf(CAT_PS)
31+
32+
/** Cat Decoder */
33+
@Suppress("MemberVisibilityCanBePrivate")
34+
object CatDecoder {
35+
36+
@JvmStatic
37+
val instance
38+
get() = this
39+
40+
/** 非猫猫码文本消息解义 */
41+
fun decodeText(str: String): String =
42+
str .replace("&#91;", "[")
43+
.replace("&#93;", "]")
44+
.replace("&#09;", "\t")
45+
.replace("&#10;", "\r")
46+
.replace("&#13;", "\n")
47+
.replace("&amp;", "&")
48+
49+
/** 非猫猫码文本消息解义,如果[str]为null则返回null */
50+
fun decodeTextOrNull(str: String?) : String? = str?.let { decodeText(it) }
51+
52+
53+
/** 猫猫码参数值消息解义 */
54+
fun decodeParams(str: String): String =
55+
str .replace("&#91;", "[")
56+
.replace("&#93;", "]")
57+
.replace("&#44;", ",")
58+
.replace("&#09;", "\t")
59+
.replace("&#10;", "\r")
60+
.replace("&#13;", "\n")
61+
.replace("&amp;", "&")
62+
63+
/** 猫猫码参数值消息解义,如果[str]为null则返回null */
64+
fun decodeParamsOrNull(str: String?): String? = str?.let { decodeParams(it) }
65+
66+
}
67+
68+
69+
public fun String.deCatParam(): String = CatDecoder.decodeParams(this)
70+
public fun String.deCatText(): String = CatDecoder.decodeText(this)
71+
72+
73+
/** Cat Encoder */
74+
@Suppress("MemberVisibilityCanBePrivate")
75+
object CatEncoder {
76+
77+
@JvmStatic
78+
val instance
79+
get() = this
80+
81+
/** 非猫猫码文本消息转义 */
82+
fun encodeText(str: String): String =
83+
str.replace("&", "&amp;")
84+
.replace("[", "&#91;")
85+
.replace("]", "&#93;")
86+
.replace("\t", "&#09;")
87+
.replace("\r", "&#10;")
88+
.replace("\n", "&#13;")
89+
90+
/** 非猫猫码文本消息转义。如果[str]为null则返回null */
91+
fun encodeTextOrNull(str: String?): String? = str?.let { encodeText(it) }
92+
93+
/** 猫猫码参数值消息转义 */
94+
fun encodeParams(str: String): String =
95+
str.replace("&", "&amp;")
96+
.replace("[", "&#91;")
97+
.replace("]", "&#93;")
98+
.replace(",", "&#44;")
99+
.replace("\t", "&#09;")
100+
.replace("\r", "&#10;")
101+
.replace("\n", "&#13;")
102+
103+
/** 猫猫码参数值消息转义。如果[str]为null则返回null */
104+
fun encodeParamsOrNull(str: String?): String? = str?.let { encodeParams(it) }
105+
106+
}
107+
108+
public fun String.enCatParam(): String = CatEncoder.encodeParams(this)
109+
public fun String.enCatText(): String = CatEncoder.encodeText(this)
110+
111+
112+
/**
113+
* 猫猫码的操作工具类
114+
*/
115+
public object CatCodeUtil : NekoAibo("CAT") {
116+
@JvmStatic
117+
val instance
118+
get() = this
119+
120+
override val catCodeHead: String = CAT_HEAD
121+
/**
122+
* 获取一个String为载体的[模板][CodeTemplate]
123+
* @see StringTemplate
124+
*/
125+
override val stringTemplate: CodeTemplate<String> get() = StringTemplate
126+
127+
/**
128+
* 获取[Neko]为载体的[模板][CodeTemplate]
129+
* @see NekoTemplate
130+
*/
131+
override val nekoTemplate: CodeTemplate<Neko> get() = NekoTemplate
132+
133+
/**
134+
* 构建一个String为载体类型的[构建器][CodeBuilder]
135+
*/
136+
override fun getStringCodeBuilder(type: String, encode: Boolean): CodeBuilder<String> = StringCodeBuilder(type, encode)
137+
138+
/**
139+
* 构建一个[Neko]为载体类型的[构建器][CodeBuilder]
140+
*/
141+
override fun getNekoBuilder(type: String, encode: Boolean): CodeBuilder<Neko> = NekoBuilder(type)
142+
143+
/**
144+
* 构建一个[Neko]为载体类型的[懒加载构建器][LazyCodeBuilder]
145+
*/
146+
override fun getLazyNekoBuilder(type: String, encode: Boolean): LazyCodeBuilder<Neko> = LazyNekoBuilder(type)
147+
148+
}
149+
150+
151+
152+
153+
154+
155+

0 commit comments

Comments
 (0)