001: /**************************************************************************/
002: /* N I C E */
003: /* A high-level object-oriented research language */
004: /* (c) Daniel Bonniot 2000 */
005: /* */
006: /* This program is free software; you can redistribute it and/or modify */
007: /* it under the terms of the GNU General Public License as published by */
008: /* the Free Software Foundation; either version 2 of the License, or */
009: /* (at your option) any later version. */
010: /* */
011: /**************************************************************************/package bossa.syntax;
012:
013: import bossa.util.*;
014:
015: /**
016: A tring with location information.
017:
018: @version $Date: 2005/01/14 16:41:27 $
019: @author Daniel Bonniot (d.bonniot@mail.dotcom.fr)
020: */
021: public class LocatedString implements Located, Comparable {
022: public LocatedString(String content, Location loc) {
023: this (content, loc, false);
024: }
025:
026: public LocatedString(String content) {
027: this (content, Location.nowhere(), false);
028: }
029:
030: /**
031: * @param content the underlying raw string
032: * @param loc the location of this string in the source
033: * @param quoted true if this string must be quoted (operators like `+`)
034: */
035: public LocatedString(String content, Location loc, boolean quoted) {
036: this .content = content;
037: this .loc = loc;
038: this .quoted = quoted;
039: }
040:
041: public String toQuotedString() {
042: if (quoted)
043: return "`" + content + "`";
044: else
045: return content;
046: }
047:
048: public String toString() {
049: return content;
050: }
051:
052: public Location location() {
053: return loc;
054: }
055:
056: /****************************************************************
057: * Wrapper for string functions
058: ****************************************************************/
059:
060: public void append(String suffix) {
061: this .content = this .content + suffix;
062: }
063:
064: public void prepend(String prefix) {
065: this .content = prefix + this .content;
066: }
067:
068: public LocatedString cloneLS() {
069: return new LocatedString(content, loc);
070: }
071:
072: public LocatedString substring(int beginIndex, int endIndex) {
073: return new LocatedString(content
074: .substring(beginIndex, endIndex), loc);
075: }
076:
077: public boolean equals(Object o) {
078: if (o instanceof LocatedString)
079: return equals((LocatedString) o);
080: else
081: return false;
082: }
083:
084: public final boolean equals(LocatedString s) {
085: boolean res = content.equals(s.content);
086: return res;
087: }
088:
089: public int hashCode() {
090: return content.hashCode();
091: }
092:
093: public int compareTo(Object o) {
094: return content.compareTo(((LocatedString) o).content);
095: }
096:
097: public String content;
098: Location loc;
099: private boolean quoted;
100: }
|