Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
11   65   6   3.67
4   30   0.55   3
3     2  
1    
 
  Element2Utf8Impl       Line # 33 11 6 100% 1.0
 
  (95)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.service.control;
17   
18    import java.util.ArrayList;
19    import java.util.List;
20   
21    import org.apache.commons.lang.ArrayUtils;
22    import org.qedeq.base.utility.StringUtility;
23    import org.qedeq.kernel.bo.common.Element2Utf8;
24    import org.qedeq.kernel.bo.service.unicode.Latex2UnicodeParser;
25    import org.qedeq.kernel.se.base.list.Element;
26   
27   
28    /**
29    * Transfer a QEDEQ formulas into UTF-8 text.
30    *
31    * @author Michael Meyling
32    */
 
33    public final class Element2Utf8Impl implements Element2Utf8 {
34   
35    /** We use this converter. */
36    private Element2LatexImpl converter;
37   
38    /**
39    * Constructor.
40    *
41    * @param converter This converter can produce at least LaTeX.
42    */
 
43  585 toggle public Element2Utf8Impl(final Element2LatexImpl converter) {
44  585 this.converter = converter;
45    }
46   
 
47  345 toggle public String getUtf8(final Element element) {
48  345 return getUtf8(element, 0)[0];
49    }
50   
 
51  1381 toggle public String[] getUtf8(final Element element, final int maxCols) {
52  1381 final String result = Latex2UnicodeParser.transform(null, converter.getLatex(element), 0);
53  1381 if (maxCols <= 0 || result.length() < maxCols) {
54  1273 return new String[] {result};
55    }
56  108 final List list = new ArrayList();
57  108 int index = 0;
58  338 while (index < result.length()) {
59  230 list.add(StringUtility.substring(result, index, maxCols));
60  230 index += maxCols;
61    }
62  108 return (String[]) list.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
63    }
64   
65    }