text processing utilities

Highlight documentation

Syntax samples

F#

01 (* The Computer Language Benchmarks Game
02  * http://shootout.alioth.debian.org/
03  * contributed by Alex Peake
04  * Literal translation of Andrei Formiga's Scala solution
05 *)
06 
07 #light
08 
09 [<EntryPoint>]
10 let main(args) =
11     let n = if args.Length > 0 then int args.[0] else 7
12     //printfn "Pfannkuchen(%d) = %d" x (fannkuch x)
13 
14     let mutable maxFlips = 0
15     let mutable permN = 0
16     let mutable j = 0
17     let mutable k = 0
18     let mutable temp = 0
19     let mutable first = 0
20     let mutable flips = 0
21     let mutable perm0 = Array.create n 0
22     let mutable perm = Array.create n 0
23     let mutable rot = Array.create n 0
24 
25     while (k < n) do
26         perm.[k] <- k + 1
27         rot.[k] <- 0
28         k <- k + 1
29     while (rot.[n - 1] < n) do
30         if (permN < 30) then
31             k <- 0
32             while (k < n) do
33                 printf "%d" perm.[k]
34                 k <- k + 1
35             printf "\n"
36             permN <- permN + 1
37 
38         flips <- 0
39         k <- 0
40         while (k < n) do
41             perm0.[k] <- perm.[k]
42             k <- k + 1
43         first <- perm0.[0]
44         while (first <> 1) do
45             k <- 0
46             while (k < (first >>> 1)) do
47                 temp <- perm0.[k]
48                 perm0.[k] <- perm0.[first - 1 - k]
49                 perm0.[first - 1 - k] <- temp;
50                 k <- k + 1
51 
52             first <- perm0.[0]
53             flips <- flips + 1
54 
55         if (flips > maxFlips) then maxFlips <- flips
56 
57         temp <- perm.[0]
58         perm.[0] <- perm.[1]
59         perm.[1] <- temp
60         rot.[1] <- rot.[1] + 1
61         j <- 1
62         while (j < n - 1 && rot.[j] > j) do
63             rot.[j] <- 0
64             j <- j + 1
65 
66             k <- 0
67             while (k < j) do
68                 temp <- perm.[k]
69                 perm.[k] <- perm.[k + 1]
70                 perm.[k + 1] <- temp
71                 k <- k + 1
72 
73             rot.[j] <- rot.[j] + 1
74 
75     printfn "Pfannkuchen(%d) = %d" n maxFlips
76     0

Perl

01 # The Computer Language Benchmarks Game
02 # http://shootout.alioth.debian.org/
03 # Initial port from C by Steve Clark
04 # Rewrite by Kalev Soikonen
05 # Modified by Kuang-che Wu
06 
07 use integer;
08 
09 sub fannkuch {
10     my ($n) = shift;
11     my ($iter, $flips, $maxflips, $i);
12     my (@q, @p, @count);
13 
14     $iter = $maxflips = 0;
15     @p = @count = (1..$n);
16     $m = $n - 1;
17 
18     TRY: while (1) {
19         if ($iter < 30) {
20             print @p, "\n";
21             $iter++;
22         }
23 
24         if ($p[0] != 1 && $p[$m] != $n) {
25             @q = @p;
26             for ($flips=0; $q[0] != 1; $flips++) {
27                 unshift @q, reverse splice @q, 0, $q[0];
28             }
29             $maxflips = $flips if ($flips > $maxflips);
30         }
31 
32         for my$i(1..$m) {
33             splice @p, $i, 0, shift @p;
34             next TRY if (--$count[$i]);
35             $count[$i] = $i + 1;
36         }
37         return $maxflips;
38     }
39 }
40 
41 for (shift || 7) {
42     print "Pfannkuchen($_) = ".fannkuch($_)."\n";
43 }

HTML + PHP + CSS + Javascript

01 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
02 <html xmlns="http://www.w3.org/1999/xhtml">
03 <head>
04 <title>Embedded syntax test</title>
05 
06     <!-- JS Snippet -->
07     <script language="JavaScript">
08     // init color to red
09     function start () {
10        document.getElementById ('status').style.color = 'red';
11        window.setTimeout ('changeStatus ()', 3 * 1000);
12     }
13 
14     // change color to green
15     function changeStatus () {
16        document.getElementById ('status').firstChild.data = 'Fertig!';
17        document.getElementById ('status').style.color = 'green';
18     }
19     </script>
20 
21     <!-- CSS Snippet -->
22     <style type="text/css">
23     <![CDATA[
24           body { background-color:#fff5ee; }
25           p    { color:#000000; font-size:12pt; font-family:'Courier New'; }
26     ]]>
27     </style>
28 </head>
29 <body onload="start()">
30 <h1>Some HTML code...</h1>
31 <span id="status">JavaScript Playground</span>
32 
33 <!-- PHP Snippet -->
34 <?php if (eregi( "^de.*" ,$_SERVER['HTTP_ACCEPT_LANGUAGE']  )){  ?>
35      <p>Deutscher Text</p>
36 <?php } else { ?>
37      <p>English text</p>
38 <?php } ?>
39 
40 </body>
41 </html>

C++ with enabled qtproject.org reference plug-in

01  // hellothreadpool/main.cpp
02  class Work : public QRunnable
03  {
04  public:
05      void run()
06      {
07          qDebug() << "Hello from thread " << QThread::currentThread();
08      }
09  };
10 
11  int main(int argc, char *argv[])
12  {
13      QCoreApplication app(argc, argv);
14      Work work;
15      work.setAutoDelete(false);
16      QThreadPool *threadPool = QThreadPool::globalInstance();
17      threadPool->start(&work);
18      qDebug() << "hello from GUI thread " << QThread::currentThread();
19      threadPool->waitForDone();
20      return 0;
21  }
Hochwald IT Xenianer.de