v4.0.6
This commit is contained in:
parent
530b8ab3cf
commit
a548316c2a
|
@ -21,8 +21,8 @@ android {
|
|||
targetSdkVersion target_sdk_version
|
||||
minSdkVersion min_sdk_version
|
||||
|
||||
versionCode 405
|
||||
versionName "4.0.5"
|
||||
versionCode 406
|
||||
versionName "4.0.6"
|
||||
applicationId "jp.juggler.subwaytooter"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package jp.juggler.subwaytooter
|
||||
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
import jp.juggler.subwaytooter.api.entity.TootAccount
|
||||
import jp.juggler.util.asciiPattern
|
||||
import jp.juggler.util.asciiPatternString
|
||||
import org.junit.Assert.assertEquals
|
||||
|
@ -11,35 +12,35 @@ import org.junit.runner.RunWith
|
|||
@RunWith(AndroidJUnit4::class)
|
||||
class TestMisskeyMentionAndroid {
|
||||
|
||||
// @Test
|
||||
// @Throws(Exception::class)
|
||||
// fun test1() {
|
||||
// fun findMention(str:String):String?{
|
||||
// val m = TootAccount.reMention.matcher(str)
|
||||
// return if(m.find()) m.group(0) else null
|
||||
// }
|
||||
// assertEquals(null, findMention(""))
|
||||
// assertEquals(null, findMention("tateisu"))
|
||||
// assertEquals("@tateisu", findMention("@tateisu"))
|
||||
// assertEquals("@tateisu", findMention("@tateisuほげ"))
|
||||
// assertEquals(
|
||||
// "@tateisu@mastodon.juggler.jp",
|
||||
// findMention("@tateisu@mastodon.juggler.jp")
|
||||
// )
|
||||
// assertEquals(
|
||||
// "@tateisu@mastodon.juggler.jp",
|
||||
// findMention("@tateisu@mastodon.juggler.jpほげ")
|
||||
// )
|
||||
// assertEquals("@tateisu", findMention("@tateisu@マストドン3.juggler.jp"))
|
||||
// assertEquals(
|
||||
// "@tateisu@xn--3-pfuzbe6htf.juggler.jp",
|
||||
// findMention("@tateisu@xn--3-pfuzbe6htf.juggler.jp")
|
||||
// )
|
||||
// }
|
||||
@Test
|
||||
fun testBracket() {
|
||||
// [] 空の文字セットはパースエラーになる。
|
||||
// val re1="""[]""".toRegex() // error 空の文字クラス
|
||||
|
||||
// [[] や [[]] はパースエラーになる。
|
||||
// val re1="""[[]""".toRegex() // error 閉じ括弧が足りない
|
||||
// val re1="""[[]]""".toRegex() // error 内側が空の文字クラス
|
||||
|
||||
// 最低でも1文字を含む。
|
||||
assertEquals(true, """[]]""".toRegex().matches("]"))
|
||||
|
||||
// 1文字あけた次からは閉じ括弧として扱われる。
|
||||
assertEquals(true, """[ ]]""".toRegex().matches(" ]"))
|
||||
|
||||
// 閉じ括弧が単体で出たら文字クラスにならない。
|
||||
assertEquals(true, """]""".toRegex().matches("]"))
|
||||
|
||||
// 閉じ括弧が足りないのはエラーになる。
|
||||
// val a="""[[ ]""".toRegex()
|
||||
|
||||
//
|
||||
assertEquals(true, """[[ ]]][ ]""".toRegex().matches(" ] "))
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testasciiPatternString() {
|
||||
fun testAsciiPattern() {
|
||||
// \w \d \W \D 以外の文字は素通しする
|
||||
assertEquals("""ab\c\\""", """ab\c\\""".asciiPatternString())
|
||||
assertEquals("""[A-Za-z0-9_]""", """\w""".asciiPatternString())
|
||||
|
@ -55,49 +56,45 @@ class TestMisskeyMentionAndroid {
|
|||
|
||||
// エスケープ文字の後に何もない場合も素通しする
|
||||
assertEquals("""\""", """\""".asciiPatternString())
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun test2() {
|
||||
// val pu = Pattern.compile("""\w+""",Pattern.UNICODE_CHARACTER_CLASS)
|
||||
// on Android: java.lang.IllegalArgumentException: Unsupported flags: 256
|
||||
|
||||
fun matchOrNull(pattern : String, input : String) : String? {
|
||||
// no UNICODE_CHARACTER_CLASS
|
||||
val m = pattern.asciiPattern().matcher(input)
|
||||
fun testMisskeyMention() {
|
||||
fun findMention(str : String) : String? {
|
||||
val m = TootAccount.reMisskeyMentionMFM.matcher(str)
|
||||
return if(m.find()) m.group(0) else null
|
||||
}
|
||||
assertEquals(null, matchOrNull("\\w+", "-"))
|
||||
assertEquals(null, matchOrNull("\\w+", "あ"))
|
||||
assertEquals("a", matchOrNull("\\w+", "a"))
|
||||
assertEquals("a", matchOrNull("\\w+", "aあ"))
|
||||
|
||||
assertEquals("0", matchOrNull("\\w+", "0"))
|
||||
assertEquals(null, matchOrNull("\\w+", "0"))
|
||||
|
||||
assertEquals("0", matchOrNull("\\d+", "0"))
|
||||
assertEquals(null, matchOrNull("\\d+", "0"))
|
||||
assertEquals(null, findMention(""))
|
||||
assertEquals(null, findMention("tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisuほげ"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jp"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jpほげ"))
|
||||
assertEquals("@tateisu", findMention("@tateisu@マストドン3.juggler.jp"))
|
||||
assertEquals(
|
||||
"@tateisu@xn--3-pfuzbe6htf.juggler.jp",
|
||||
findMention("@tateisu@xn--3-pfuzbe6htf.juggler.jp")
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun test3(){
|
||||
// [] 空の文字セットはパースエラーになる。
|
||||
// val re1="""[]""".toRegex()
|
||||
|
||||
// 最低でも1文字を含む。
|
||||
assertEquals(true,"""[]]""".toRegex().matches("]"))
|
||||
|
||||
// 1文字あけた次からは閉じ括弧として扱われる。
|
||||
assertEquals(true,"""[ ]]""".toRegex().matches(" ]"))
|
||||
|
||||
// 閉じ括弧が単体で出たら文字クラスにならない。
|
||||
assertEquals(true,"""]""".toRegex().matches("]"))
|
||||
|
||||
// 閉じ括弧が足りないのはエラーになる。
|
||||
// val a="""[[ ]""".toRegex()
|
||||
|
||||
//
|
||||
assertEquals(true,"""[[ ]]][ ]""".toRegex().matches(" ] "))
|
||||
|
||||
@Test
|
||||
fun testMastodonMention() {
|
||||
fun findMention(str : String) : String? {
|
||||
val m = TootAccount.reCountMention.matcher(str)
|
||||
return if(m.find()) m.group(0) else null
|
||||
}
|
||||
assertEquals(null, findMention(""))
|
||||
assertEquals(null, findMention("tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisuほげ"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jp"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jpほげ"))
|
||||
assertEquals("@tateisu@マストドン3.juggler.jp", findMention("@tateisu@マストドン3.juggler.jp"))
|
||||
assertEquals(
|
||||
"@tateisu@xn--3-pfuzbe6htf.juggler.jp",
|
||||
findMention("@tateisu@xn--3-pfuzbe6htf.juggler.jp")
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -500,7 +500,7 @@ open class TootAccount(parser : TootParser, src : JsonObject) {
|
|||
private const val reMastodonMention =
|
||||
"""(?<=^|[^/$reRubyWord])@(($reMastodonUserName)(?:@[$reRubyWord.-]+[A-Za-z0-9]+)?)"""
|
||||
|
||||
private val reCountMention = reMastodonMention.asciiPattern()
|
||||
val reCountMention = reMastodonMention.asciiPattern()
|
||||
|
||||
fun countText(s : String) : Int {
|
||||
return s
|
||||
|
|
|
@ -3,18 +3,18 @@ package jp.juggler.util
|
|||
import java.util.regex.Pattern
|
||||
|
||||
/*
|
||||
java.util.regex.Patternは Oracle JVM と Android で大きく異なる。
|
||||
Androidの正規表現エンジンはICUベースで、文字クラスは常にUnicodeで扱われる
|
||||
|
||||
java.util.regex.Pattern は Oracle JVM と Android で大きく異なる。
|
||||
Androidの正規表現エンジンはICUベースで、
|
||||
AndroidのAPIリファレンスで UNICODE_CHARACTER_CLASS を見ると
|
||||
"This flag has no effect on Android, unicode character classes are always used." と書いてある。
|
||||
\w \d \s などの文字クラスの扱いに違いがある。
|
||||
|
||||
JVMでUNICODE_CHARACTER_CLASSフラグなしの場合はこう
|
||||
\s 空白文字: [\t\n\x0B\f\r]
|
||||
\d 数字: [0-9]
|
||||
\w 単語構成文字: [a-zA-Z_0-9]
|
||||
|
||||
JVMでJVMでUNICODE_CHARACTER_CLASSフラグありの場合はこう
|
||||
JVMでUNICODE_CHARACTER_CLASSフラグありの場合はこう
|
||||
\s 空白文字: \p{IsWhite_Space}
|
||||
\d 数字: \p{IsDigit}
|
||||
\w 単語構成文字: [\p{Alpha}\p{gc=Mn}\p{gc=Me}\p{gc=Mc}\p{Digit}\p{gc=Pc}\p{IsJoin_Control}]
|
||||
|
@ -26,7 +26,6 @@ http://userguide.icu-project.org/strings/regexp
|
|||
\d Match any character with the Unicode General Category of Nd (Number, Decimal Digit.)
|
||||
|
||||
とりあえず \d \D と \w と \W は凄く困るので 正規表現を書き換えてなんとかしたい。
|
||||
|
||||
なおJVMもICUも [A-Z[a-z]] と書くと [A-Za-z]と同じ事になる。
|
||||
よって [^\w.-] を [^[A-Za-z0-9].-] に変換しても問題ない。
|
||||
困るのは\W や \D の方だが、STのコードを見た感じ\Wは使っていないし、¥Dを文字クラスの中で使っていることもなかった
|
||||
|
|
|
@ -1,30 +1,41 @@
|
|||
package jp.juggler.subwaytooter
|
||||
|
||||
import jp.juggler.subwaytooter.api.entity.TootAccount
|
||||
import jp.juggler.util.asciiPatternString
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class TestMisskeyMention {
|
||||
|
||||
// @Test
|
||||
// fun test1(){
|
||||
// fun findMention(str:String):String?{
|
||||
// val m = TootAccount.reMention.matcher(str)
|
||||
// return if(m.find()) m.group(0) else null
|
||||
// }
|
||||
// assertEquals(null,findMention(""))
|
||||
// assertEquals(null,findMention("tateisu"))
|
||||
// assertEquals("@tateisu",findMention("@tateisu"))
|
||||
// assertEquals("@tateisu",findMention("@tateisuほげ"))
|
||||
// assertEquals("@tateisu@mastodon.juggler.jp",findMention("@tateisu@mastodon.juggler.jp"))
|
||||
// assertEquals("@tateisu@mastodon.juggler.jp",findMention("@tateisu@mastodon.juggler.jpほげ"))
|
||||
// assertEquals("@tateisu",findMention("@tateisu@マストドン3.juggler.jp"))
|
||||
// assertEquals("@tateisu@xn--3-pfuzbe6htf.juggler.jp",findMention("@tateisu@xn--3-pfuzbe6htf.juggler.jp"))
|
||||
// }
|
||||
@Test
|
||||
fun testBracket() {
|
||||
// [] 空の文字セットはパースエラーになる。
|
||||
// val re1="""[]""".toRegex() // error 空の文字クラス
|
||||
|
||||
// [[] や [[]] はパースエラーになる。
|
||||
// val re1="""[[]""".toRegex() // error 閉じ括弧が足りない
|
||||
// val re1="""[[]]""".toRegex() // error 内側が空の文字クラス
|
||||
|
||||
// 最低でも1文字を含む。
|
||||
assertEquals(true, """[]]""".toRegex().matches("]"))
|
||||
|
||||
// 1文字あけた次からは閉じ括弧として扱われる。
|
||||
assertEquals(true, """[ ]]""".toRegex().matches(" ]"))
|
||||
|
||||
// 閉じ括弧が単体で出たら文字クラスにならない。
|
||||
assertEquals(true, """]""".toRegex().matches("]"))
|
||||
|
||||
// 閉じ括弧が足りないのはエラーになる。
|
||||
// val a="""[[ ]""".toRegex()
|
||||
|
||||
//
|
||||
assertEquals(true, """[[ ]]][ ]""".toRegex().matches(" ] "))
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testasciiPatternString() {
|
||||
fun testAsciiPattern() {
|
||||
// \w \d \W \D 以外の文字は素通しする
|
||||
assertEquals("""ab\c\\""", """ab\c\\""".asciiPatternString())
|
||||
assertEquals("""[A-Za-z0-9_]""", """\w""".asciiPatternString())
|
||||
|
@ -43,28 +54,42 @@ class TestMisskeyMention {
|
|||
|
||||
}
|
||||
|
||||
@Test fun test3(){
|
||||
// [] 空の文字セットはパースエラーになる。
|
||||
// val re1="""[]""".toRegex() // error 空の文字クラス
|
||||
|
||||
// [[] や [[]] はパースエラーになる。
|
||||
// val re1="""[[]""".toRegex() // error 閉じ括弧が足りない
|
||||
// val re1="""[[]]""".toRegex() // error 内側が空の文字クラス
|
||||
|
||||
// 最低でも1文字を含む。
|
||||
assertEquals(true,"""[]]""".toRegex().matches("]"))
|
||||
|
||||
// 1文字あけた次からは閉じ括弧として扱われる。
|
||||
assertEquals(true,"""[ ]]""".toRegex().matches(" ]"))
|
||||
|
||||
// 閉じ括弧が単体で出たら文字クラスにならない。
|
||||
assertEquals(true,"""]""".toRegex().matches("]"))
|
||||
|
||||
// 閉じ括弧が足りないのはエラーになる。
|
||||
// val a="""[[ ]""".toRegex()
|
||||
|
||||
//
|
||||
assertEquals(true,"""[[ ]]][ ]""".toRegex().matches(" ] "))
|
||||
|
||||
@Test
|
||||
fun testMisskeyMention() {
|
||||
fun findMention(str : String) : String? {
|
||||
val m = TootAccount.reMisskeyMentionMFM.matcher(str)
|
||||
return if(m.find()) m.group(0) else null
|
||||
}
|
||||
assertEquals(null, findMention(""))
|
||||
assertEquals(null, findMention("tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisuほげ"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jp"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jpほげ"))
|
||||
assertEquals("@tateisu", findMention("@tateisu@マストドン3.juggler.jp"))
|
||||
assertEquals(
|
||||
"@tateisu@xn--3-pfuzbe6htf.juggler.jp",
|
||||
findMention("@tateisu@xn--3-pfuzbe6htf.juggler.jp")
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMastodonMention() {
|
||||
fun findMention(str : String) : String? {
|
||||
val m = TootAccount.reCountMention.matcher(str)
|
||||
return if(m.find()) m.group(0) else null
|
||||
}
|
||||
assertEquals(null, findMention(""))
|
||||
assertEquals(null, findMention("tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisu"))
|
||||
assertEquals("@tateisu", findMention("@tateisuほげ"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jp"))
|
||||
assertEquals("@tateisu@mastodon.juggler.jp", findMention("@tateisu@mastodon.juggler.jpほげ"))
|
||||
assertEquals("@tateisu@マストドン3.juggler.jp", findMention("@tateisu@マストドン3.juggler.jp"))
|
||||
assertEquals(
|
||||
"@tateisu@xn--3-pfuzbe6htf.juggler.jp",
|
||||
findMention("@tateisu@xn--3-pfuzbe6htf.juggler.jp")
|
||||
)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue