Skip to content

Commit 62b051a

Browse files
committed
another code refactor
1 parent 58e1f49 commit 62b051a

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/parser/ParseResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ParseResult(
6060
* The style keys of the content. The style at higher index of the list will
6161
* override the style of the lower index.
6262
*/
63-
protected var styleKeys: MutableList<String>
63+
private var styleKeys: MutableList<String>
6464

6565
/**
6666
* Get the style keys represented by one string key, see

codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/prettify/lang/LangN.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import com.wakaztahir.codeeditor.utils.new
3030
*/
3131
class LangN : Lang() {
3232
companion object {
33-
protected var keywords = ("abstract|and|as|base|catch|class|def|delegate|enum|event|extern|false|finally|"
33+
private var keywords = ("abstract|and|as|base|catch|class|def|delegate|enum|event|extern|false|finally|"
3434
+ "fun|implements|interface|internal|is|macro|match|matches|module|mutable|namespace|new|"
3535
+ "null|out|override|params|partial|private|protected|public|ref|sealed|static|struct|"
3636
+ "syntax|this|throw|true|try|type|typeof|using|variant|virtual|volatile|when|where|with|"
@@ -84,7 +84,7 @@ class LangN : Lang() {
8484
)
8585
fallthroughStylePatterns.new(
8686
Prettify.PR_KEYWORD,
87-
Regex("^(?:" + keywords + ")\\\\b"),
87+
Regex("^(?:$keywords)\\\\b"),
8888
null
8989
)
9090
fallthroughStylePatterns.new(

codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/prettify/parser/CombinePrefixPattern.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CombinePrefixPattern {
3939
}
4040

4141
/**
42-
* Given a group of [java.util.regex.Pattern]s, returns a `RegExp` that globally
42+
* Given a group of [Regex]s, returns a `RegExp` that globally
4343
* matches the union of the sets of strings matched by the input RegExp.
4444
* Since it matches globally, if the input strings have a start-of-input
4545
* anchor (/^.../), it is ignored for the purposes of unioning.
@@ -53,7 +53,7 @@ class CombinePrefixPattern {
5353
var i: Int = 0
5454
val n: Int = regexs.size
5555
while (i < n) {
56-
val regex: Regex = regexs.get(i)
56+
val regex: Regex = regexs[i]
5757
if (regex.options.contains(RegexOption.IGNORE_CASE)) {
5858
ignoreCase = true
5959
} else if (Util.test(
@@ -87,7 +87,7 @@ class CombinePrefixPattern {
8787
)
8888
}
8989

90-
internal fun decodeEscape(charsetPart: String): Int {
90+
private fun decodeEscape(charsetPart: String): Int {
9191
val cc0: Int = charsetPart[0].code
9292
if (cc0 != 92 /* \\ */) {
9393
return cc0
@@ -102,7 +102,7 @@ class CombinePrefixPattern {
102102
}
103103
}
104104

105-
internal fun encodeEscape(charCode: Int): String {
105+
private fun encodeEscape(charCode: Int): String {
106106
if (charCode < 0x20) {
107107
return (if (charCode < 0x10) "\\x0" else "\\x") + charCode.toString(16)
108108
}
@@ -111,7 +111,7 @@ class CombinePrefixPattern {
111111
return if (((charCode == '\\'.code) || (charCode == '-'.code) || (charCode == ']'.code) || (charCode == '^'.code))) "\\" + ch else ch
112112
}
113113

114-
internal fun toChars(codePoint: Int): CharArray {
114+
private fun toChars(codePoint: Int): CharArray {
115115
return if (codePoint ushr 16 == 0) {
116116
charArrayOf(codePoint.toChar())
117117
} else if (codePoint ushr 16 < 0X10FFFF + 1 ushr 16) {
@@ -125,7 +125,7 @@ class CombinePrefixPattern {
125125
}
126126
}
127127

128-
internal fun caseFoldCharset(charSet: String?): String {
128+
private fun caseFoldCharset(charSet: String?): String {
129129
val charsetParts = Util.match(
130130
Regex(
131131
("\\\\u[0-9A-Fa-f]{4}"
@@ -183,14 +183,14 @@ class CombinePrefixPattern {
183183

184184
// [[1, 10], [3, 4], [8, 12], [14, 14], [16, 16], [17, 17]]
185185
// -> [[1, 12], [14, 14], [16, 17]]
186-
ranges.sortWith({ a, b -> if (a[0] != b[0]) (a[0] - b[0]) else (b[1] - a[1]) })
186+
ranges.sortWith { a, b -> if (a[0] != b[0]) (a[0] - b[0]) else (b[1] - a[1]) }
187187
// Collections.sort(ranges, Comparator { a, b -> if (a[0] !== b[0]) (a[0] - b[0]) else (b[1] - a[1]) })
188188
val consolidatedRanges: MutableList<List<Int>> = ArrayList()
189189
// List<Integer> lastRange = listOf(new Integer[]{0, 0});
190190
var lastRange: MutableList<Int> = ArrayList(listOf(0, 0))
191191
for (i in ranges.indices) {
192192
val range = ranges[i]
193-
if (lastRange[1] != null && range[0] <= lastRange[1] + 1) {
193+
if (range[0] <= lastRange[1] + 1) {
194194
lastRange[1] = (lastRange[1]).coerceAtLeast(range[1])
195195
} else {
196196
// reference of lastRange is added
@@ -211,7 +211,7 @@ class CombinePrefixPattern {
211211
return join(out)
212212
}
213213

214-
internal fun allowAnywhereFoldCaseAndRenumberGroups(regex: Regex): String {
214+
private fun allowAnywhereFoldCaseAndRenumberGroups(regex: Regex): String {
215215
// Split into character sets, escape sequences, punctuation strings
216216
// like ('(', '(?:', ')', '^'), and runs of characters that do not
217217
// include any of the above.
@@ -242,11 +242,11 @@ class CombinePrefixPattern {
242242
var i: Int = 0
243243
var groupIndex: Int = 0
244244
while (i < n) {
245-
val p: String = parts.get(i)
245+
val p: String = parts[i]
246246
if ((p == "(")) {
247247
// groups are 1-indexed, so max group index is count of '('
248248
++groupIndex
249-
} else if ('\\' == p!![0]) {
249+
} else if ('\\' == p[0]) {
250250
try {
251251
val decimalValue: Int = abs(p.substring(1).toInt())
252252
if (decimalValue <= groupIndex) {
@@ -275,17 +275,17 @@ class CombinePrefixPattern {
275275
var i: Int = 0
276276
var groupIndex: Int = 0
277277
while (i < n) {
278-
val p: String = parts.get(i)
278+
val p: String = parts[i]
279279
if ((p == "(")) {
280280
++groupIndex
281-
if (capturedGroups.get(groupIndex) == null) {
281+
if (capturedGroups[groupIndex] == null) {
282282
parts[i] = "(?:"
283283
}
284-
} else if ('\\' == p!!.get(0)) {
284+
} else if ('\\' == p[0]) {
285285
try {
286286
val decimalValue: Int = abs(p.substring(1).toInt())
287287
if (decimalValue <= groupIndex) {
288-
parts[i] = "\\" + capturedGroups.get(decimalValue)
288+
parts[i] = "\\" + capturedGroups[decimalValue]
289289
}
290290
} catch (ex: NumberFormatException) {
291291
}
@@ -297,7 +297,7 @@ class CombinePrefixPattern {
297297
// Remove any prefix anchors so that the output will match anywhere.
298298
// ^^ really does mean an anchored match though.
299299
for (i in 0 until n) {
300-
if (("^" == parts[i]) && "^" != parts.get(i + 1)) {
300+
if (("^" == parts[i]) && "^" != parts[i + 1]) {
301301
parts[i] = ""
302302
}
303303
}
@@ -307,7 +307,7 @@ class CombinePrefixPattern {
307307
if (regex.options.contains(RegexOption.IGNORE_CASE) && needToFoldCase) {
308308
for (i in 0 until n) {
309309
val p = parts[i]
310-
val ch0: Char = if (p.length > 0) p[0] else '0'
310+
val ch0: Char = if (p.isNotEmpty()) p[0] else '0'
311311
if (p.length >= 2 && ch0 == '[') {
312312
parts[i] = caseFoldCharset(p)
313313
} else if (ch0 != '\\') {
@@ -335,7 +335,7 @@ class CombinePrefixPattern {
335335
}
336336
var appendIndex = 0
337337
while (matchResult != null) {
338-
val cc = matchResult.groups.get(0)?.value?.get(0)?.code
338+
val cc = matchResult.groups[0]?.value?.get(0)?.code
339339
mySb.append(p.substring(appendIndex,matchResult.range.first))
340340
appendIndex = matchResult.range.last
341341
if (cc != null) {

codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/prettify/parser/Job.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Job constructor(basePos: Int = 0, sourceCode: String? = "") {
3737
/**
3838
* The source code.
3939
*/
40-
internal var sourceCode: String
40+
private var sourceCode: String
4141

4242
/**
4343
* The parsed results. n<sup>th</sup> items are starting position position,

codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/prettify/parser/Prettify.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class Prettify {
244244
/**
245245
* @const
246246
*/
247-
val regexAny = if (!regexExcls.isEmpty()) "." else "[\\S\\s]"
247+
val regexAny = if (regexExcls.isNotEmpty()) "." else "[\\S\\s]"
248248

249249
/**
250250
* @const
@@ -808,11 +808,11 @@ class Prettify {
808808
companion object {
809809

810810
// Keyword lists for various languages.
811-
const val FLOW_CONTROL_KEYWORDS = "break,continue,do,else,for,if,return,while"
812-
const val C_KEYWORDS = (FLOW_CONTROL_KEYWORDS + "," + "auto,case,char,const,default,"
811+
private const val FLOW_CONTROL_KEYWORDS = "break,continue,do,else,for,if,return,while"
812+
private const val C_KEYWORDS = (FLOW_CONTROL_KEYWORDS + "," + "auto,case,char,const,default,"
813813
+ "double,enum,extern,float,goto,inline,int,long,register,short,signed,"
814814
+ "sizeof,static,struct,switch,typedef,union,unsigned,void,volatile")
815-
const val COMMON_KEYWORDS = (C_KEYWORDS + "," + "catch,class,delete,false,import,"
815+
private const val COMMON_KEYWORDS = (C_KEYWORDS + "," + "catch,class,delete,false,import,"
816816
+ "new,operator,private,protected,public,this,throw,true,try,typeof")
817817
const val CPP_KEYWORDS = (COMMON_KEYWORDS + "," + "alignof,align_union,asm,axiom,bool,"
818818
+ "concept,concept_map,const_cast,constexpr,decltype,delegate,"
@@ -823,7 +823,7 @@ class Prettify {
823823
+ "abstract,assert,boolean,byte,extends,final,finally,implements,import,"
824824
+ "instanceof,interface,null,native,package,strictfp,super,synchronized,"
825825
+ "throws,transient")
826-
const val KOTLIN_KEYWORDS = (JAVA_KEYWORDS + ","
826+
private const val KOTLIN_KEYWORDS = (JAVA_KEYWORDS + ","
827827
+ "as,as?,fun,in,!in,object,typealias,val,var,when,by,constructor,delegate,dynamic,field,"
828828
+ "file,get,init,set,value,where,actual,annotation,companion,crossinline,data,enum,expect,"
829829
+ "external,field,infix,inline,inner,internal,it,lateinit,noinline,open,operator,out,override,"
@@ -955,7 +955,7 @@ class Prettify {
955955
* @param basePos the index of sourceCode within the chunk of source
956956
* whose decorations are already present on out.
957957
*/
958-
protected fun appendDecorations(
958+
private fun appendDecorations(
959959
basePos: Int,
960960
sourceCode: String?,
961961
langHandler: CreateSimpleLexer?,

codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/prettify/parser/Util.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ object Util {
174174
throw NullPointerException("argument 'strings' cannot be null")
175175
}
176176
val sb = StringBuilder()
177-
if (strings.size != 0) {
177+
if (strings.isNotEmpty()) {
178178
sb.append(strings[0])
179179
var i = 1
180180
val iEnd = strings.size

0 commit comments

Comments
 (0)