1 /***********************************************************************
2  * Copyright (c) 2013-2024 Commonwealth Computer Research, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Apache License, Version 2.0
5  * which accompanies this distribution and is available at
6  * http://www.opensource.org/licenses/apache2.0.php.
7  ***********************************************************************/
8 
9 package org.locationtech.geomesa.utils.conversions
10 
11 object StringOps {
12 
13   implicit class RichString(val string: String) extends AnyVal {
14 
15     /**
16      * For every line in this string:
17      *
18      * Strip a leading prefix consisting of blanks or control characters,
19      * followed by separator from the line,
20      * followed by any whitespace
21      *
22      * @param separator line separator
23      * @return
24      */
25     def stripMarginAndWhitespace(separator: Char = '|'): String = {
26       val trimmed = new StringBuilder()
27       string.linesWithSeparators.foreach { line =>
28         var index = line.indexWhere(_ > ' ')
29         if (index == -1) {
30           trimmed.append(line)
31         } else {
32           if (line.charAt(index) == separator) {
33             index += 1
34           }
35           while (index < line.length && line.charAt(index).isWhitespace) {
36             index += 1
37           }
38           if (index < line.length) {
39             trimmed.append(line.substring(index))
40           }
41         }
42       }
43       trimmed.toString
44     }
45   }
46 }
Line Stmt Id Pos Tree Symbol Tests Code
26 4765 965 - 984 Apply scala.collection.mutable.StringBuilder.<init> new scala.`package`.StringBuilder()
27 4766 991 - 997 Select org.locationtech.geomesa.utils.conversions.StringOps.RichString.string RichString.this.string
27 4794 991 - 1466 Apply scala.collection.Iterator.foreach scala.Predef.augmentString(RichString.this.string).linesWithSeparators.foreach[Any](((line: String) => { var index: Int = scala.Predef.augmentString(line).indexWhere(((x$1: Char) => x$1.>(' '))); if (index.==(-1)) trimmed.append(line) else { if (line.charAt(index).==(separator)) index = index.+(1) else (); while$1(){ if (index.<(line.length()).&&(scala.Predef.charWrapper(line.charAt(index)).isWhitespace)) { index = index.+(1); while$1() } else () }; if (index.<(line.length())) trimmed.append(line.substring(index)) else () } }))
28 4767 1072 - 1079 Apply scala.Char.> x$1.>(' ')
28 4768 1056 - 1080 Apply scala.collection.GenSeqLike.indexWhere scala.Predef.augmentString(line).indexWhere(((x$1: Char) => x$1.>(' ')))
29 4769 1093 - 1104 Apply scala.Int.== index.==(-1)
30 4770 1118 - 1138 Apply scala.collection.mutable.StringBuilder.append trimmed.append(line)
30 4771 1118 - 1138 Block scala.collection.mutable.StringBuilder.append trimmed.append(line)
31 4793 1154 - 1458 Block <nosymbol> { if (line.charAt(index).==(separator)) index = index.+(1) else (); while$1(){ if (index.<(line.length()).&&(scala.Predef.charWrapper(line.charAt(index)).isWhitespace)) { index = index.+(1); while$1() } else () }; if (index.<(line.length())) trimmed.append(line.substring(index)) else () }
32 4772 1170 - 1201 Apply scala.Char.== line.charAt(index).==(separator)
32 4775 1166 - 1166 Literal <nosymbol> ()
32 4776 1166 - 1166 Block <nosymbol> ()
33 4773 1217 - 1227 Apply scala.Int.+ index.+(1)
33 4774 1217 - 1227 Assign <nosymbol> index = index.+(1)
35 4777 1265 - 1276 Apply java.lang.String.length line.length()
35 4778 1280 - 1298 Apply java.lang.String.charAt line.charAt(index)
35 4779 1280 - 1311 Select scala.runtime.RichChar.isWhitespace scala.Predef.charWrapper(line.charAt(index)).isWhitespace
35 4780 1257 - 1311 Apply scala.Boolean.&& index.<(line.length()).&&(scala.Predef.charWrapper(line.charAt(index)).isWhitespace)
35 4783 1327 - 1337 Block <nosymbol> { index = index.+(1); while$1() }
35 4784 1250 - 1250 Literal <nosymbol> ()
35 4785 1250 - 1250 Block <nosymbol> ()
36 4781 1327 - 1337 Apply scala.Int.+ index.+(1)
36 4782 1333 - 1333 Apply org.locationtech.geomesa.utils.conversions.StringOps.RichString.while$1 while$1()
38 4786 1372 - 1383 Apply java.lang.String.length line.length()
38 4787 1364 - 1383 Apply scala.Int.< index.<(line.length())
38 4791 1360 - 1360 Literal <nosymbol> ()
38 4792 1360 - 1360 Block <nosymbol> ()
39 4788 1414 - 1435 Apply java.lang.String.substring line.substring(index)
39 4789 1399 - 1436 Apply scala.collection.mutable.StringBuilder.append trimmed.append(line.substring(index))
39 4790 1399 - 1436 Block scala.collection.mutable.StringBuilder.append trimmed.append(line.substring(index))
43 4795 1473 - 1489 Apply scala.collection.mutable.StringBuilder.toString trimmed.toString()