@@ -542,8 +542,6 @@ object URI {
542542 // (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]) # 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 (IPv4-Embedded IPv6 Address)
543543 }
544544
545- private val ipv6Re = new RegExp (" ^" + ipv6address + " $" , " i" )
546-
547545 private val ipv6ReStr = " ^" + ipv6address + " $"
548546
549547 /** Test whether a host string is an IPv6 address.
@@ -555,7 +553,7 @@ object URI {
555553 java.util.regex.Pattern .CASE_INSENSITIVE )
556554 pattern.matcher(host).matches()
557555 } {
558- ipv6Re .test(host)
556+ new RegExp (ipv6ReStr, " i " ) .test(host)
559557 }
560558 }
561559
@@ -707,8 +705,6 @@ object URI {
707705 " ^(?:" + absoluteURI + " |" + relativeURI + " )(?:#" + fragment + " )?$"
708706 }
709707
710- private val uriRe = new RegExp (uriReStr, " i" )
711-
712708 /** Parse a URI string, returning an Array[String] of matched groups
713709 * (null for non-matching groups), or null if the string is not a valid URI.
714710 * Uses js.RegExp for JS targets and java.util.regex.Pattern for pure Wasm.
@@ -731,7 +727,7 @@ object URI {
731727 arr
732728 }
733729 } {
734- val result = uriRe .exec(str)
730+ val result = new RegExp (uriReStr, " i " ) .exec(str)
735731 if (result == null ) {
736732 null
737733 } else {
@@ -911,17 +907,8 @@ object URI {
911907 }
912908 }
913909
914- private val quoteStr : js.Function1 [String , String ] = { (str : String ) =>
915- val buf = StandardCharsets .UTF_8 .encode(str)
916-
917- var res = " "
918- while (buf.hasRemaining()) {
919- val c = buf.get() & 0xff
920- res += (if (c <= 0xf ) " %0" else " %" ) + Integer .toHexString(c).toUpperCase
921- }
922-
923- res
924- }
910+ private def quoteStr : js.Function1 [String , String ] =
911+ (str : String ) => quoteStrFn(str)
925912
926913 /** Encode a matched string as percent-encoded UTF-8 bytes (pure Scala). */
927914 private def quoteStrFn (str : String ): String = {
@@ -964,15 +951,13 @@ object URI {
964951 " [\u0000 - \" #/<>?@\\ [-\\ ^`{-}" +
965952 " \u007f -\u00a0\u1680\u2000 -\u200a\u202f\u205f\u3000\u2028\u2029 ]|" +
966953 " %(?![0-9a-f]{2})"
967- private val userInfoQuoteRe = new RegExp (userInfoQuoteReStr, " ig" )
968-
969954 /** Quote any character not in unreserved, punct, escaped or other */
970955 private def quoteUserInfo (str : String ): String = {
971956 LinkingInfo .linkTimeIf(LinkingInfo .targetPureWasm) {
972957 quoteWithPattern(str, userInfoQuoteReStr, caseInsensitive = true )
973958 } {
974959 import js .JSStringOps ._
975- str.jsReplace(userInfoQuoteRe , quoteStr)
960+ str.jsReplace(new RegExp (userInfoQuoteReStr, " ig " ) , quoteStr)
976961 }
977962 }
978963
@@ -985,8 +970,6 @@ object URI {
985970 " [\u0000 - \" #<>?\\ [-\\ ^`{-}" +
986971 " \u007f -\u00a0\u1680\u2000 -\u200a\u202f\u205f\u3000\u2028\u2029 ]|" +
987972 " %(?![0-9a-f]{2})"
988- private val pathQuoteRe = new RegExp (pathQuoteReStr, " ig" )
989-
990973 /** Quote any character not in unreserved, punct, escaped, other or equal
991974 * to '/' or '@'
992975 */
@@ -995,7 +978,7 @@ object URI {
995978 quoteWithPattern(str, pathQuoteReStr, caseInsensitive = true )
996979 } {
997980 import js .JSStringOps ._
998- str.jsReplace(pathQuoteRe , quoteStr)
981+ str.jsReplace(new RegExp (pathQuoteReStr, " ig " ) , quoteStr)
999982 }
1000983 }
1001984
@@ -1012,8 +995,6 @@ object URI {
1012995 " [\u0000 - \" #/<>?\\ ^`{-}" +
1013996 " \u007f -\u00a0\u1680\u2000 -\u200a\u202f\u205f\u3000\u2028\u2029 ]|" +
1014997 " %(?![0-9a-f]{2})"
1015- private val authorityQuoteRe = new RegExp (authorityQuoteReStr, " ig" )
1016-
1017998 /** Quote any character not in unreserved, punct, escaped, other or equal
1018999 * to '@'
10191000 */
@@ -1022,7 +1003,7 @@ object URI {
10221003 quoteWithPattern(str, authorityQuoteReStr, caseInsensitive = true )
10231004 } {
10241005 import js .JSStringOps ._
1025- str.jsReplace(authorityQuoteRe , quoteStr)
1006+ str.jsReplace(new RegExp (authorityQuoteReStr, " ig " ) , quoteStr)
10261007 }
10271008 }
10281009
@@ -1033,15 +1014,13 @@ object URI {
10331014 " [\u0000 - \" #<>@\\ ^`{-}" +
10341015 " \u007f -\u00a0\u1680\u2000 -\u200a\u202f\u205f\u3000\u2028\u2029 ]|" +
10351016 " %(?![0-9a-f]{2})"
1036- private val illegalQuoteRe = new RegExp (illegalQuoteReStr, " ig" )
1037-
10381017 /** Quote any character not in unreserved, reserved, escaped or other */
10391018 private def quoteIllegal (str : String ): String = {
10401019 LinkingInfo .linkTimeIf(LinkingInfo .targetPureWasm) {
10411020 quoteWithPattern(str, illegalQuoteReStr, caseInsensitive = true )
10421021 } {
10431022 import js .JSStringOps ._
1044- str.jsReplace(illegalQuoteRe , quoteStr)
1023+ str.jsReplace(new RegExp (illegalQuoteReStr, " ig " ) , quoteStr)
10451024 }
10461025 }
10471026
@@ -1051,14 +1030,12 @@ object URI {
10511030 * surrogates that need to be encoded in one shot.
10521031 */
10531032 private val nonASCIIQuoteReStr = " [^\u0000 -\u007F ]+"
1054- private val nonASCIIQuoteRe = new RegExp (nonASCIIQuoteReStr, " g" )
1055-
10561033 private def quoteNonASCII (str : String ): String = {
10571034 LinkingInfo .linkTimeIf(LinkingInfo .targetPureWasm) {
10581035 quoteWithPattern(str, nonASCIIQuoteReStr, caseInsensitive = false )
10591036 } {
10601037 import js .JSStringOps ._
1061- str.jsReplace(nonASCIIQuoteRe , quoteStr)
1038+ str.jsReplace(new RegExp (nonASCIIQuoteReStr, " g " ) , quoteStr)
10621039 }
10631040 }
10641041
0 commit comments