packages feed

highlighting-kate-0.6.3: tests/abc.kotlin.html

<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style type="text/css">div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style></head><body><div class="sourceCode"><pre class="sourceCode"><code class="sourceCode"><span class="kw" title="KeywordTok">import</span> <span class="im" title="ImportTok">java.util.Arrays</span>

<span class="co" title="CommentTok">/*</span>
<span class="co" title="CommentTok">    Swap elements i and j of a Kotlin Array.</span>
<span class="co" title="CommentTok"> */</span>
<span class="kw" title="KeywordTok">fun</span> &lt;<span class="dt" title="DataTypeTok">T</span>&gt; <span class="fu" title="FunctionTok">Array</span>&lt;<span class="dt" title="DataTypeTok">T</span>&gt;.<span class="fu" title="FunctionTok">swap</span>(<span class="va" title="VariableTok">i</span>: <span class="dt" title="DataTypeTok">Int</span>, <span class="va" title="VariableTok">j</span>: <span class="dt" title="DataTypeTok">Int</span>) {
    <span class="kw" title="KeywordTok">val</span> <span class="va" title="VariableTok">tmp</span> = <span class="kw" title="KeywordTok">this</span>[i]
    <span class="kw" title="KeywordTok">this</span>[i] = <span class="kw" title="KeywordTok">this</span>[j]
    <span class="kw" title="KeywordTok">this</span>[j] = tmp
}

<span class="kw" title="KeywordTok">data</span> <span class="kw" title="KeywordTok">class</span> Block(<span class="kw" title="KeywordTok">val</span> <span class="va" title="VariableTok">block</span>: <span class="dt" title="DataTypeTok">String</span>)

/*
 *  Not the most elegant way but interesting from an highlighting perspective ;)
 */
<span class="kw" title="KeywordTok">public</span> <span class="kw" title="KeywordTok">class</span> ABC() {
    <span class="kw" title="KeywordTok">class</span> <span class="kw" title="KeywordTok">object</span> {

        <span class="kw" title="KeywordTok">public</span> <span class="kw" title="KeywordTok">fun</span> <span class="fu" title="FunctionTok">canMakeWord</span>(<span class="va" title="VariableTok">word</span>: <span class="dt" title="DataTypeTok">String</span>, <span class="va" title="VariableTok">blocks</span>: <span class="dt" title="DataTypeTok">Array</span>&lt;<span class="va" title="VariableTok">Block</span>&gt;): <span class="dt" title="DataTypeTok">Boolean</span> {
            <span class="cf" title="ControlFlowTok">if</span> (word.length() == <span class="dv" title="DecValTok">0</span>)
                <span class="kw" title="KeywordTok">return</span> <span class="kw" title="KeywordTok">true</span>

            <span class="kw" title="KeywordTok">val</span> <span class="va" title="VariableTok">c</span> = Character.toUpperCase(word.charAt(<span class="dv" title="DecValTok">0</span>))
            <span class="cf" title="ControlFlowTok">for</span> (i <span class="kw" title="KeywordTok">in</span> <span class="dv" title="DecValTok">0</span>..blocks.size - <span class="dv" title="DecValTok">1</span>) {
                <span class="kw" title="KeywordTok">val</span> <span class="va" title="VariableTok">b</span> = blocks[i]
                <span class="cf" title="ControlFlowTok">if</span> (Character.toUpperCase(b.block.charAt(<span class="dv" title="DecValTok">0</span>)) != c &amp;&amp; Character.toUpperCase(b.block.charAt(<span class="dv" title="DecValTok">1</span>)) != c)
                    <span class="cf" title="ControlFlowTok">continue</span>
                blocks.swap(<span class="dv" title="DecValTok">0</span>, i)
                <span class="cf" title="ControlFlowTok">if</span> (canMakeWord(word.substring(<span class="dv" title="DecValTok">1</span>), Arrays.copyOfRange(blocks, <span class="dv" title="DecValTok">1</span>, blocks.size)))
                    <span class="kw" title="KeywordTok">return</span> <span class="kw" title="KeywordTok">true</span>
                blocks.swap(<span class="dv" title="DecValTok">0</span>, i)
            }

            <span class="kw" title="KeywordTok">return</span> <span class="kw" title="KeywordTok">false</span>
        }

        <span class="kw" title="KeywordTok">public</span> <span class="kw" title="KeywordTok">fun</span> <span class="fu" title="FunctionTok">main</span>(<span class="va" title="VariableTok">args</span>: <span class="dt" title="DataTypeTok">Array</span>&lt;<span class="va" title="VariableTok">String</span>&gt;) {

            <span class="kw" title="KeywordTok">val</span> <span class="va" title="VariableTok">blocksString</span> = array(<span class="st" title="StringTok">&quot;BO&quot;</span>, <span class="st" title="StringTok">&quot;XK&quot;</span>, <span class="st" title="StringTok">&quot;DQ&quot;</span>, <span class="st" title="StringTok">&quot;CP&quot;</span>, <span class="st" title="StringTok">&quot;NA&quot;</span>, <span class="st" title="StringTok">&quot;GT&quot;</span>, <span class="st" title="StringTok">&quot;RE&quot;</span>, <span class="st" title="StringTok">&quot;TG&quot;</span>, <span class="st" title="StringTok">&quot;QD&quot;</span>, <span class="st" title="StringTok">&quot;FS&quot;</span>, <span class="st" title="StringTok">&quot;JW&quot;</span>,
                                             <span class="st" title="StringTok">&quot;HU&quot;</span>, <span class="st" title="StringTok">&quot;VI&quot;</span>, <span class="st" title="StringTok">&quot;AN&quot;</span>, <span class="st" title="StringTok">&quot;OB&quot;</span>, <span class="st" title="StringTok">&quot;ER&quot;</span>, <span class="st" title="StringTok">&quot;FS&quot;</span>, <span class="st" title="StringTok">&quot;LY&quot;</span>, <span class="st" title="StringTok">&quot;PC&quot;</span>, <span class="st" title="StringTok">&quot;ZM&quot;</span>);

            <span class="kw" title="KeywordTok">val</span> <span class="va" title="VariableTok">blocks</span> = Array(blocksString.size, { s -&gt; Block(blocksString[s])})

            <span class="kw" title="KeywordTok">val</span> <span class="va" title="VariableTok">words</span> = array(<span class="st" title="StringTok">&quot;&quot;</span>, <span class="st" title="StringTok">&quot;A&quot;</span>, <span class="st" title="StringTok">&quot;BARK&quot;</span>, <span class="st" title="StringTok">&quot;book&quot;</span>, <span class="st" title="StringTok">&quot;treat&quot;</span>, <span class="st" title="StringTok">&quot;COMMON&quot;</span>, <span class="st" title="StringTok">&quot;SQuAd&quot;</span>, <span class="st" title="StringTok">&quot;CONFUSE&quot;</span>);

            <span class="cf" title="ControlFlowTok">for</span> (word <span class="kw" title="KeywordTok">in</span> words) {
                System.<span class="kw" title="KeywordTok">out</span>.println(<span class="st" title="StringTok">&quot;${word}: &quot;</span> + canMakeWord(<span class="st" title="StringTok">&quot;${word}&quot;</span>, blocks))
            }

        }
    }
}

<span class="kw" title="KeywordTok">fun</span> <span class="fu" title="FunctionTok">main</span>(<span class="va" title="VariableTok">args</span>: <span class="dt" title="DataTypeTok">Array</span>&lt;<span class="va" title="VariableTok">String</span>&gt;) = ABC.main(args)</code></pre></div></body>