mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[textmate] introduce NotMatchingRegexFacade
GitOrigin-RevId: 22b7dbb4b8375e0aa0f8c70b2eb7174948fbd5b9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bda068983f
commit
1ef0d54b39
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.plugins.textmate.regex
|
||||
|
||||
import kotlinx.coroutines.Runnable
|
||||
import org.jetbrains.plugins.textmate.regex.MatchData.Companion.NOT_MATCHED
|
||||
|
||||
interface RegexFacade {
|
||||
fun match(string: TextMateString, checkCancelledCallback: Runnable?): MatchData
|
||||
@@ -16,4 +17,23 @@ interface RegexFactory {
|
||||
fun regex(pattern: CharSequence): RegexFacade
|
||||
|
||||
fun string(string: CharSequence): TextMateString
|
||||
}
|
||||
}
|
||||
|
||||
object NotMatchingRegexFacade : RegexFacade {
|
||||
override fun match(
|
||||
string: TextMateString,
|
||||
checkCancelledCallback: Runnable?
|
||||
): MatchData {
|
||||
return NOT_MATCHED
|
||||
}
|
||||
|
||||
override fun match(
|
||||
string: TextMateString,
|
||||
byteOffset: Int,
|
||||
matchBeginPosition: Boolean,
|
||||
matchBeginString: Boolean,
|
||||
checkCancelledCallback: Runnable?
|
||||
): MatchData {
|
||||
return NOT_MATCHED
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.intellij.textmate.joni
|
||||
|
||||
import org.jcodings.specific.UTF8Encoding
|
||||
import org.jetbrains.plugins.textmate.regex.NotMatchingRegexFacade
|
||||
import org.jetbrains.plugins.textmate.regex.RegexFacade
|
||||
import org.jetbrains.plugins.textmate.regex.RegexFactory
|
||||
import org.jetbrains.plugins.textmate.regex.TextMateString
|
||||
@@ -13,20 +14,19 @@ import org.slf4j.LoggerFactory
|
||||
|
||||
class JoniRegexFactory : RegexFactory {
|
||||
companion object {
|
||||
private val FAILED_REGEX: Regex = Regex("^$", UTF8Encoding.INSTANCE)
|
||||
private val LOGGER: Logger = LoggerFactory.getLogger(JoniRegexFactory::class.java)
|
||||
}
|
||||
|
||||
override fun regex(pattern: CharSequence): RegexFacade {
|
||||
val bytes = pattern.toString().toByteArray(Charsets.UTF_8)
|
||||
val regex = try {
|
||||
Regex(bytes, 0, bytes.size, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, WarnCallback.NONE)
|
||||
return try {
|
||||
val regex = Regex(bytes, 0, bytes.size, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, WarnCallback.NONE)
|
||||
JoniRegexFacade(regex)
|
||||
}
|
||||
catch (e: JOniException) {
|
||||
LOGGER.info("Failed to parse textmate regex '{}' with {}: {}", pattern, e::class.java.getName(), e.message)
|
||||
FAILED_REGEX
|
||||
NotMatchingRegexFacade
|
||||
}
|
||||
return JoniRegexFacade(regex)
|
||||
}
|
||||
|
||||
override fun string(string: CharSequence): TextMateString {
|
||||
|
||||
Reference in New Issue
Block a user