Skip to content

Instantly share code, notes, and snippets.

@leodagdag
Created April 1, 2012 16:15
Show Gist options
  • Save leodagdag/2276707 to your computer and use it in GitHub Desktop.
Save leodagdag/2276707 to your computer and use it in GitHub Desktop.
Scala example : Parse String
val suffix: Map[Symbol,Map[Symbol,Tuple2[String,String]]] =
"""
en=y:year,years|M:month,months|d:day,days|h:hour,hours|m:minute,minutes|s:seconde,secondes
fr=y:année,années|M:mois,mois|d:jour,jours|h:heure,heures|m:minute,minutes|s:seconde,secondes
""".split('\n').map(_.trim).filter(_.size > 0).map(_.split('=')).map {
line: Array[String] => // ["en","y:year,years|M:month,months|d:day,days|h:hour,hours|m:minute,minutes|s:seconde,secondes"]
Symbol(line(0)) -> line(1).split('|').map {
period: String => // "y:year,years"
Symbol(period(0).toString) -> period.drop(2).mkString
}.toMap.map {
words: Tuple2[Symbol, String] => // ('y,"year,years")(Symbol, String)
val word: Array[String] = words._2.split(',').map(" " + _ + " ")
words._1 -> Tuple2(word(0), word(1))
}.toMap
}.toMap
println(suffix.get(lang).get('y)._1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment