Browse Source
This commit implements StringToRegexConverter in Java in order to avoid circular dependencies between Java and Kotlin codes that can break IDE support, and for consistency with the rest of the codebase. See gh-24311pull/31113/head
2 changed files with 39 additions and 19 deletions
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.core.convert.support; |
||||
|
||||
import kotlin.text.Regex; |
||||
|
||||
import org.springframework.core.convert.converter.Converter; |
||||
|
||||
/** |
||||
* Converts from a String to a {@link Regex}. |
||||
* |
||||
* @author Stephane Nicoll |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
class StringToRegexConverter implements Converter<String, Regex> { |
||||
|
||||
@Override |
||||
public Regex convert(String source) { |
||||
if (source.isEmpty()) { |
||||
return null; |
||||
} |
||||
return new Regex(source); |
||||
} |
||||
|
||||
} |
@ -1,19 +0,0 @@
@@ -1,19 +0,0 @@
|
||||
package org.springframework.core.convert.support |
||||
|
||||
import org.springframework.core.convert.converter.Converter |
||||
|
||||
/** |
||||
* Converts from a String to a [Regex]. |
||||
* |
||||
* @author Stephane Nicoll |
||||
*/ |
||||
class StringToRegexConverter : Converter<String, Regex> { |
||||
|
||||
override fun convert(source: String): Regex? { |
||||
if (source.isEmpty()) { |
||||
return null |
||||
} |
||||
return source.toRegex() |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue