• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.jetbrains.dokka.Model
2 
3 import org.jsoup.helper.StringUtil.isWhitespace
4 import org.jsoup.nodes.TextNode
5 
6 class CodeNode(text: String, baseUri: String): TextNode(text, baseUri) {
7 
textnull8     override fun text(): String {
9         return normaliseInitialWhitespace(wholeText.removePrefix("<code>")
10             .removeSuffix("</code>"))
11     }
12 
normaliseInitialWhitespacenull13     private fun normaliseInitialWhitespace(text: String): String {
14         val sb = StringBuilder(text.length)
15         removeInitialWhitespace(sb, text)
16         return sb.toString()
17     }
18 
19     /**
20      * Remove initial whitespace.
21      * @param accum builder to append to
22      * @param string string to remove the initial whitespace
23      */
removeInitialWhitespacenull24     private fun removeInitialWhitespace(accum: StringBuilder, string: String) {
25         var reachedNonWhite = false
26 
27         val len = string.length
28         var c: Int
29         var i = 0
30         while (i < len) {
31             c = string.codePointAt(i)
32             if (isWhitespace(c) && !reachedNonWhite) {
33                 i += Character.charCount(c)
34                 continue
35             } else {
36                 accum.appendCodePoint(c)
37                 reachedNonWhite = true
38             }
39             i += Character.charCount(c)
40         }
41     }
42 }