diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-12-11 19:56:22 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-12-11 19:56:22 +0100 |
commit | 3bfd83971ec48102fd1e711236f5a313c6a1ce3e (patch) | |
tree | a75d929d7fc7e2c0ac4b5e620a4019a4936abeeb /docs/examples/xml/phonebook/phonebook3.scala | |
parent | e1c6dd965aa4249f715bbb2832df182cc5505853 (diff) | |
parent | 9cdbe28c00b39c51ae9afe3066c8b44a6e5f6f96 (diff) | |
download | scala-3bfd83971ec48102fd1e711236f5a313c6a1ce3e.tar.gz scala-3bfd83971ec48102fd1e711236f5a313c6a1ce3e.tar.bz2 scala-3bfd83971ec48102fd1e711236f5a313c6a1ce3e.zip |
Merge commit '9cdbe28' into merge/2.10.x-to-master
Conflicts:
build.examples.xml
build.xml
docs/examples/actors/pingpong.scala
docs/examples/fors.scala
docs/examples/iterators.scala
docs/examples/jolib/Ref.scala
docs/examples/jolib/parallelOr.scala
docs/examples/monads/callccInterpreter.scala
docs/examples/monads/directInterpreter.scala
docs/examples/monads/errorInterpreter.scala
docs/examples/monads/simpleInterpreter.scala
docs/examples/monads/stateInterpreter.scala
docs/examples/parsing/ArithmeticParser.scala
docs/examples/patterns.scala
docs/examples/pilib/elasticBuffer.scala
docs/examples/pilib/handover.scala
docs/examples/pilib/piNat.scala
docs/examples/typeinf.scala
src/build/pack.xml
Diffstat (limited to 'docs/examples/xml/phonebook/phonebook3.scala')
-rw-r--r-- | docs/examples/xml/phonebook/phonebook3.scala | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/docs/examples/xml/phonebook/phonebook3.scala b/docs/examples/xml/phonebook/phonebook3.scala deleted file mode 100644 index 12f2deaa79..0000000000 --- a/docs/examples/xml/phonebook/phonebook3.scala +++ /dev/null @@ -1,81 +0,0 @@ -package phonebook; - -object phonebook3 { - - import scala.xml.{Elem, Node, Text} ; - import scala.xml.PrettyPrinter ; - import Node.NoAttributes ; - - /* this method "changes" (returns an updated copy) of the phonebook when the - * entry for Name exists. If it has an attribute "where" whose value is equal to the - * parameter Where, it is changed, otherwise, it is added. - */ - def change ( phonebook:Node, Name:String, Where:String, newPhone:String ) = { - - /** this nested function walks through tree, and returns an updated copy of it */ - def copyOrChange ( ch: Iterator[Node] ) = { - - import xml.Utility.{trim,trimProper} //removes whitespace nodes, which are annoying in matches - - for( val c <- ch ) yield - trimProper(c) match { - - // if the node is the particular entry we are looking for, return an updated copy - - case x @ <entry><name>{ Text(Name) }</name>{ ch1 @ _* }</entry> => - - var updated = false; - val ch2 = for(c <- ch1) yield c match { // does it have the phone number? - - case y @ <phone>{ _* }</phone> if y \ "@where" == Where => - updated = true - <phone where={ Where }>{ newPhone }</phone> - - case y => y - - } - if( !updated ) { // no, so we add as first entry - - <entry> - <name>{ Name }</name> - <phone where={ Where }>{ newPhone }</phone> - { ch1 } - </entry> - - } else { // yes, and we changed it as we should - - <entry> - { ch2 } - </entry> - - } - // end case x @ <entry>... - - // other entries are copied without changing them - - case x => - x - - } - } ; // for ... yield ... returns an Iterator[Node] - - // decompose phonebook, apply updates - phonebook match { - case <phonebook>{ ch @ _* }</phonebook> => - <phonebook>{ copyOrChange( ch.iterator ) }</phonebook> - } - - } - - val pb2 = - change( phonebook1.labPhoneBook, "John", "work", "+41 55 555 55 55" ); - - val pp = new PrettyPrinter( 80, 5 ); - - def main( args:Array[String] ) = { - Console.println("---before---"); - Console.println( pp.format( phonebook1.labPhoneBook )); - Console.println("---after---"); - Console.println( pp.format( pb2 )); - } -} |