• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.jsoup;
2 
3 import java.util.regex.Pattern;
4 
5 /**
6  Text utils to ease testing
7 
8  @author Jonathan Hedley, jonathan@hedley.net */
9 public class TextUtil {
10     static Pattern stripper = Pattern.compile("\\r?\\n\\s*");
11     static Pattern stripLines = Pattern.compile("\\r?\\n?");
12     static Pattern spaceCollapse = Pattern.compile("\\s{2,}");
13     static Pattern tagSpaceCollapse = Pattern.compile(">\\s+<");
14     static Pattern stripCRs = Pattern.compile("\\r*");
15 
stripNewlines(String text)16     public static String stripNewlines(String text) {
17         return stripper.matcher(text).replaceAll("");
18     }
19 
normalizeSpaces(String text)20     public static String normalizeSpaces(String text) {
21         text = stripLines.matcher(text).replaceAll("");
22         text = stripper.matcher(text).replaceAll("");
23         text = spaceCollapse.matcher(text).replaceAll(" ");
24         text = tagSpaceCollapse.matcher(text).replaceAll("><");
25         return text;
26     }
27 
stripCRs(String text)28     public static String stripCRs(String text) {
29         return stripCRs.matcher(text).replaceAll("");
30     }
31 }
32