String upper/lower case no longer locale dependent

Fixed many instances of the Turkish i bug.

Spare a thought for the poor Turks!
This commit is contained in:
James Roper 2013-09-24 12:17:46 +10:00 committed by Mark Harrah
parent 5ecc16df24
commit 743ce99315
11 changed files with 27 additions and 15 deletions

View File

@ -3,10 +3,12 @@
*/
package sbt
import java.util.Locale
object StringUtilities
{
@deprecated("Different use cases require different normalization. Use Project.normalizeModuleID or normalizeProjectID instead.", "0.13.0")
def normalize(s: String) = s.toLowerCase.replaceAll("""\W+""", "-")
def normalize(s: String) = s.toLowerCase(Locale.ENGLISH).replaceAll("""\W+""", "-")
def nonEmpty(s: String, label: String)
{
require(s.trim.length > 0, label + " cannot be empty.")

View File

@ -5,7 +5,7 @@ package xsbt.boot
import Pre._
import java.io.{File, FileInputStream, FileOutputStream}
import java.util.Properties
import java.util.{Locale, Properties}
import scala.collection.immutable.List
object Initialize
@ -19,7 +19,7 @@ object Initialize
{
case None => declined("")
case Some(line) =>
line.toLowerCase match
line.toLowerCase(Locale.ENGLISH) match
{
case "y" | "yes" => process(file, spec, selectCreate)
case "s" => process(file, spec, selectQuick)

View File

@ -6,6 +6,7 @@ package xsbt.boot
import scala.collection.immutable.List
import java.io.{File, FileFilter}
import java.net.{URL, URLClassLoader}
import java.util.Locale
object Pre
{
@ -79,6 +80,6 @@ object Pre
}
if(f.exists) f.delete()
}
final val isWindows: Boolean = System.getProperty("os.name").toLowerCase.contains("windows")
final val isWindows: Boolean = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
final val isCygwin: Boolean = isWindows && java.lang.Boolean.getBoolean("sbt.cygwin")
}

View File

@ -15,6 +15,7 @@ package sbt
import java.io.File
import java.net.URI
import java.util.Locale
/** This class is the entry point for sbt.*/
final class xMain extends xsbti.AppMain
@ -394,7 +395,7 @@ object BuiltinCommands
def loadFailed = Command.command(LoadFailed)(handleLoadFailed)
@tailrec def handleLoadFailed(s: State): State =
{
val result = (SimpleReader.readLine("Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? ") getOrElse Quit).toLowerCase
val result = (SimpleReader.readLine("Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? ") getOrElse Quit).toLowerCase(Locale.ENGLISH)
def matches(s: String) = !result.isEmpty && (s startsWith result)
if(result.isEmpty || matches("retry"))

View File

@ -5,6 +5,7 @@ package sbt
import java.io.File
import java.net.URI
import java.util.Locale
import Project.{Initialize => _, Setting => _, _}
import Keys.{appConfiguration, stateBuildStructure, commands, configuration, historyPath, projectCommand, sessionSettings, shellPrompt, thisProject, thisProjectRef, watch}
import Scope.{GlobalScope,ThisScope}
@ -178,7 +179,7 @@ object Project extends ProjectExtra
val refined = if(!validProjectIDStart(attempt.substring(0, 1)) ) "root-" + attempt else attempt
validProjectID(refined).toLeft(refined)
}
private[this] def normalizeBase(s: String) = s.toLowerCase.replaceAll("""\W+""", "-")
private[this] def normalizeBase(s: String) = s.toLowerCase(Locale.ENGLISH).replaceAll("""\W+""", "-")
/** Normalize a String so that it is suitable for use as a dependency management module identifier.
* This is a best effort implementation, since valid characters are not documented or consistent.*/

View File

@ -9,6 +9,7 @@ import java.net.URI
import BuildLoader.ResolveInfo
import RichURI.fromURI
import java.util.Locale
object Resolvers
{
@ -112,8 +113,8 @@ object Resolvers
private lazy val onWindows = {
val os = System.getenv("OSTYPE")
val isCygwin = (os != null) && os.toLowerCase.contains("cygwin")
val isWindows = System.getProperty("os.name", "").toLowerCase.contains("windows")
val isCygwin = (os != null) && os.toLowerCase(Locale.ENGLISH).contains("cygwin")
val isWindows = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).contains("windows")
isWindows && !isCygwin
}

View File

@ -4,6 +4,7 @@
package sbt
import java.io.{File,OutputStream}
import java.util.Locale
@deprecated("Use ForkOptions", "0.13.0")
trait ForkJava
@ -131,7 +132,7 @@ object Fork
private[this] def optionsTooLong(options: Seq[String]): Boolean =
options.mkString(" ").length > MaxConcatenatedOptionLength
private[this] val isWindows: Boolean = System.getProperty("os.name").toLowerCase.contains("windows")
private[this] val isWindows: Boolean = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
private[this] def convertClasspathToEnv(options: Seq[String]): (Option[String], Seq[String]) =
{
val (preCP, cpAndPost) = options.span(opt => !isClasspathOption(opt))

View File

@ -3,6 +3,8 @@
*/
package sbt
import java.util.Locale
object Util
{
def makeList[T](size: Int, value: T): List[T] = List.fill(size)(value)
@ -31,13 +33,13 @@ object Util
def hypenToCamel(s: String): String = hyphenToCamel(s)
def hyphenToCamel(s: String): String =
if(hasHyphen(s))
Hypen.replaceAllIn(s, _.group(1).toUpperCase)
Hypen.replaceAllIn(s, _.group(1).toUpperCase(Locale.ENGLISH))
else
s
private[this] lazy val Camel = """(\p{javaLowerCase})(\p{javaUpperCase})""".r
def camelToHypen(s: String): String =
Camel.replaceAllIn(s, m => m.group(1) + "-" + m.group(2).toLowerCase)
Camel.replaceAllIn(s, m => m.group(1) + "-" + m.group(2).toLowerCase(Locale.ENGLISH))
def quoteIfKeyword(s: String): String = if(ScalaKeywords.values(s)) '`' + s + '`' else s
}

View File

@ -4,6 +4,7 @@
package xsbt.datatype
import java.io.File
import java.util.Locale
/** Generates a datatype hierarchy from a definition file.*/
object GenerateDatatypes
@ -18,7 +19,7 @@ object GenerateDatatypes
}
else
{
val immutable = args(0).trim.toLowerCase == "immutable"
val immutable = args(0).trim.toLowerCase(Locale.ENGLISH) == "immutable"
val packageName = args(1).trim
require(!packageName.isEmpty)

View File

@ -9,6 +9,7 @@ import sbt.Path
import sbt.IO.write
import Generator._
import java.util.Locale
abstract class GeneratorBase(val basePkgName: String, val baseDirectory: File) extends NotNull
{
@ -129,7 +130,7 @@ object Generator
def fieldToString(name: String, single: Boolean) = "\"" + name + ": \" + " + fieldString(name + "()", single)
def fieldString(arg: String, single: Boolean) = if(single) arg else "Arrays.toString(" + arg + ")"
def normalize(m: MemberDef): MemberDef =
m.mapType(tpe => if(primitives(tpe.toLowerCase)) tpe.toLowerCase else tpe)
m.mapType(tpe => if(primitives(tpe.toLowerCase(Locale.ENGLISH))) tpe.toLowerCase(Locale.ENGLISH) else tpe)
private val primitives = Set("int", "boolean", "float", "long", "short", "byte", "char", "double")
def toStringMethod(c: ClassDef): String =

View File

@ -3,7 +3,8 @@
*/
package sbt
import java.io.{BufferedWriter, PrintStream, PrintWriter}
import java.io.{BufferedWriter, PrintStream, PrintWriter}
import java.util.Locale
object ConsoleLogger
{
@ -99,7 +100,7 @@ object ConsoleLogger
val noSuppressedMessage = (_: SuppressedTraceContext) => None
private[this] def os = System.getProperty("os.name")
private[this] def isWindows = os.toLowerCase.indexOf("windows") >= 0
private[this] def isWindows = os.toLowerCase(Locale.ENGLISH).indexOf("windows") >= 0
def apply(out: PrintStream): ConsoleLogger = apply(ConsoleOut.printStreamOut(out))
def apply(out: PrintWriter): ConsoleLogger = apply(ConsoleOut.printWriterOut(out))