diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-12-09 11:06:22 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-12-09 17:11:05 -0800 |
commit | e55510607031aaf7b8473453f83c44a26c9b97e0 (patch) | |
tree | 987d4aeeef387ed435acc64ffadfdf78e6f65bce /docs/examples/xml | |
parent | dc6dd58d9da441b591580684f3d2f38d7898e7d4 (diff) | |
download | scala-e55510607031aaf7b8473453f83c44a26c9b97e0.tar.gz scala-e55510607031aaf7b8473453f83c44a26c9b97e0.tar.bz2 scala-e55510607031aaf7b8473453f83c44a26c9b97e0.zip |
Remove docs/examples; they reside at scala/scala-dist
Diffstat (limited to 'docs/examples/xml')
-rw-r--r-- | docs/examples/xml/phonebook/embeddedBook.scala | 26 | ||||
-rw-r--r-- | docs/examples/xml/phonebook/phonebook.scala | 38 | ||||
-rw-r--r-- | docs/examples/xml/phonebook/phonebook1.scala | 21 | ||||
-rw-r--r-- | docs/examples/xml/phonebook/phonebook2.scala | 25 | ||||
-rw-r--r-- | docs/examples/xml/phonebook/phonebook3.scala | 81 | ||||
-rw-r--r-- | docs/examples/xml/phonebook/verboseBook.scala | 24 |
6 files changed, 0 insertions, 215 deletions
diff --git a/docs/examples/xml/phonebook/embeddedBook.scala b/docs/examples/xml/phonebook/embeddedBook.scala deleted file mode 100644 index 3286485f0b..0000000000 --- a/docs/examples/xml/phonebook/embeddedBook.scala +++ /dev/null @@ -1,26 +0,0 @@ -/* examples/phonebook/embeddedBook.scala */ -package phonebook - -object embeddedBook { - - val company = <a href="http://acme.org">ACME</a> - val first = "Burak" - val last = "Emir" - val location = "work" - - val embBook = - <phonebook> - <descr> - This is the <b>phonebook</b> of the - {company} corporation. - </descr> - <entry> - <name>{ first+" "+last }</name> - <phone where={ location }>+41 21 693 68 {val x = 60 + 7; x}</phone> - </entry> - </phonebook>; - - def main(args: Array[String]) = - Console.println( embBook ) - -} diff --git a/docs/examples/xml/phonebook/phonebook.scala b/docs/examples/xml/phonebook/phonebook.scala deleted file mode 100644 index 3c0dfbd837..0000000000 --- a/docs/examples/xml/phonebook/phonebook.scala +++ /dev/null @@ -1,38 +0,0 @@ -package phonebook ; - -object phonebook { - - val labPhoneBook = - <phonebook> - <descr> - This is the <b>phonebook</b> of the - <a href="http://acme.org">ACME</a> corporation. - </descr> - <entry> - <name>Burak</name> - <phone where="work"> +41 21 693 68 67</phone> - <phone where="mobile">+41 79 602 23 23</phone> - </entry> - </phonebook>; - - Console.println( labPhoneBook ); - - // XML is immutable - adding an element - - import scala.xml.{ Node, Text }; - - def add( phonebook:Node, newEntry:Node ):Node = phonebook match { - case <phonebook>{ ch @ _* }</phonebook> => - <phonebook>{ ch }{ newEntry }</phonebook> - } - - val pb2 = - add( labPhoneBook, - <entry> - <name>Kim</name> - <phone where="work"> +41 21 111 11 11</phone> - </entry> ); - - def main(args:Array[String]) = Console.println( pb2 ); - -} diff --git a/docs/examples/xml/phonebook/phonebook1.scala b/docs/examples/xml/phonebook/phonebook1.scala deleted file mode 100644 index 316c6c1995..0000000000 --- a/docs/examples/xml/phonebook/phonebook1.scala +++ /dev/null @@ -1,21 +0,0 @@ -/* examples/phonebook/phonebook1.scala */ -package phonebook - -object phonebook1 { - - val labPhoneBook = - <phonebook> - <descr> - This is the <b>phonebook</b> of the - <a href="http://acme.org">ACME</a> corporation. - </descr> - <entry> - <name>Burak Emir</name> - <phone where="work">+41 21 693 68 67</phone> - </entry> - </phonebook>; - - def main(args: Array[String]) = - Console.println( labPhoneBook ) - -} diff --git a/docs/examples/xml/phonebook/phonebook2.scala b/docs/examples/xml/phonebook/phonebook2.scala deleted file mode 100644 index 2a708daf7c..0000000000 --- a/docs/examples/xml/phonebook/phonebook2.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* examples/xml/phonebook/phonebook2.scala */ -package phonebook; - -object phonebook2 { - - import scala.xml.Node - - /** adds an entry to a phonebook */ - def add( p: Node, newEntry: Node ): Node = p match { - - case <phonebook>{ ch @ _* }</phonebook> => - - <phonebook>{ ch }{ newEntry }</phonebook> - } - - val pb2 = - add( phonebook1.labPhoneBook, - <entry> - <name>Kim</name> - <phone where="work">+41 21 111 11 11</phone> - </entry> ); - - def main( args: Array[String] ) = - Console.println( pb2 ) -} 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 )); - } -} diff --git a/docs/examples/xml/phonebook/verboseBook.scala b/docs/examples/xml/phonebook/verboseBook.scala deleted file mode 100644 index 2dcb155480..0000000000 --- a/docs/examples/xml/phonebook/verboseBook.scala +++ /dev/null @@ -1,24 +0,0 @@ -/* examples/xml/phonebook/verboseBook.scala */ -package phonebook - -object verboseBook { - - import scala.xml.{ UnprefixedAttribute, Elem, Node, Null, Text, TopScope } - - val pbookVerbose = - Elem(null, "phonebook", Null, TopScope, - Elem(null, "descr", Null, TopScope, - Text("This is a "), - Elem(null, "b", Null, TopScope, Text("sample")), - Text("description") - ), - Elem(null, "entry", Null, TopScope, - Elem(null, "name", Null, TopScope, Text("Burak Emir")), - Elem(null, "phone", new UnprefixedAttribute("where","work", Null), TopScope, - Text("+41 21 693 68 67")) - ) - ) - - def main(args: Array[String]) = - Console.println( pbookVerbose ) -} |