2010-11-15 20:35:36 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2019-01-16 18:34:41 +00:00
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
|
|
|
*
|
|
|
|
* http://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* http://plantuml.com/paypal
|
|
|
|
*
|
2010-11-15 20:35:36 +00:00
|
|
|
* This file is part of PlantUML.
|
|
|
|
*
|
|
|
|
* PlantUML is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PlantUML distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
2013-12-10 19:36:50 +00:00
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
2010-11-15 20:35:36 +00:00
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
2015-06-20 10:54:49 +00:00
|
|
|
*
|
2010-11-15 20:35:36 +00:00
|
|
|
*/
|
2015-06-20 10:54:49 +00:00
|
|
|
package net.sourceforge.plantuml;
|
|
|
|
|
2019-06-26 19:24:49 +00:00
|
|
|
import net.sourceforge.plantuml.command.regex.FoxSignature;
|
|
|
|
|
|
|
|
final public class StringLocated {
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
private final String s;
|
2015-06-20 10:54:49 +00:00
|
|
|
private final LineLocation location;
|
2019-03-29 22:14:07 +00:00
|
|
|
private final String preprocessorError;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public StringLocated(String s, LineLocation location) {
|
2017-03-15 19:13:31 +00:00
|
|
|
this(s, location, null);
|
|
|
|
}
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2019-08-26 17:07:21 +00:00
|
|
|
return s;
|
2019-03-29 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public StringLocated(String s, LineLocation location, String preprocessorError) {
|
2015-06-20 10:54:49 +00:00
|
|
|
if (s == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
this.s = s;
|
|
|
|
this.location = location;
|
2017-03-15 19:13:31 +00:00
|
|
|
this.preprocessorError = preprocessorError;
|
2015-06-20 10:54:49 +00:00
|
|
|
}
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public StringLocated withErrorPreprocessor(String preprocessorError) {
|
|
|
|
return new StringLocated(s, location, preprocessorError);
|
2011-01-05 18:23:06 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public StringLocated sub(int start, int end) {
|
|
|
|
return new StringLocated(this.getString().substring(start, end), this.getLocation(),
|
|
|
|
this.getPreprocessorError());
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2019-06-26 19:24:49 +00:00
|
|
|
private StringLocated trimmed;
|
|
|
|
|
|
|
|
public StringLocated getTrimmed() {
|
|
|
|
if (trimmed == null) {
|
|
|
|
this.trimmed = new StringLocated(StringUtils.trin(this.getString()), location, preprocessorError);
|
|
|
|
trimmed.fox = this.fox;
|
|
|
|
trimmed.trimmed = trimmed;
|
|
|
|
}
|
|
|
|
return trimmed;
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public StringLocated removeInnerComment() {
|
2017-12-11 21:02:10 +00:00
|
|
|
final String string = s.toString();
|
|
|
|
final String trim = string.replace('\t', ' ').trim();
|
|
|
|
if (trim.startsWith("/'")) {
|
|
|
|
final int idx = string.indexOf("'/");
|
|
|
|
if (idx != -1) {
|
2019-03-29 22:14:07 +00:00
|
|
|
return new StringLocated(removeSpecialInnerComment(s.substring(idx + 2, s.length())), location,
|
2018-01-04 22:32:45 +00:00
|
|
|
preprocessorError);
|
2017-12-11 21:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (trim.endsWith("'/")) {
|
|
|
|
final int idx = string.lastIndexOf("/'");
|
|
|
|
if (idx != -1) {
|
2019-03-29 22:14:07 +00:00
|
|
|
return new StringLocated(removeSpecialInnerComment(s.substring(0, idx)), location, preprocessorError);
|
2017-12-11 21:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-04 22:32:45 +00:00
|
|
|
if (trim.contains("/'''") && trim.contains("'''/")) {
|
2019-03-29 22:14:07 +00:00
|
|
|
return new StringLocated(removeSpecialInnerComment(s), location, preprocessorError);
|
2018-01-04 22:32:45 +00:00
|
|
|
}
|
2017-12-11 21:02:10 +00:00
|
|
|
return this;
|
|
|
|
}
|
2018-01-04 22:32:45 +00:00
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
private String removeSpecialInnerComment(String s) {
|
2018-01-04 22:32:45 +00:00
|
|
|
if (s.contains("/'''") && s.contains("'''/")) {
|
|
|
|
return s.replaceAll("/'''[-\\w]*'''/", "");
|
|
|
|
|
|
|
|
}
|
2019-03-29 22:14:07 +00:00
|
|
|
return s;
|
2018-01-04 22:32:45 +00:00
|
|
|
}
|
2019-03-29 22:14:07 +00:00
|
|
|
|
|
|
|
public String getString() {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LineLocation getLocation() {
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPreprocessorError() {
|
|
|
|
return preprocessorError;
|
|
|
|
}
|
|
|
|
|
2019-06-26 19:24:49 +00:00
|
|
|
private long fox = -1;
|
|
|
|
|
|
|
|
public long getFoxSignature() {
|
|
|
|
if (fox == -1) {
|
|
|
|
fox = FoxSignature.getFoxSignature(getString());
|
|
|
|
}
|
|
|
|
return fox;
|
|
|
|
}
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|