1 package nom.tam.fits.utilities;
2
3 /*
4 * #%L
5 * nom.tam FITS library
6 * %%
7 * Copyright (C) 1996 - 2024 nom-tam-fits
8 * %%
9 * This is free and unencumbered software released into the public domain.
10 *
11 * Anyone is free to copy, modify, publish, use, compile, sell, or
12 * distribute this software, either in source code form or as a compiled
13 * binary, for any purpose, commercial or non-commercial, and by any
14 * means.
15 *
16 * In jurisdictions that recognize copyright laws, the author or authors
17 * of this software dedicate any and all copyright interest in the
18 * software to the public domain. We make this dedication for the benefit
19 * of the public at large and to the detriment of our heirs and
20 * successors. We intend this dedication to be an overt act of
21 * relinquishment in perpetuity of all present and future rights to this
22 * software under copyright law.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 * OTHER DEALINGS IN THE SOFTWARE.
31 * #L%
32 */
33
34 /**
35 * This class is a pointer into a part of an other string, it can be manipulated by changing the position pointers into
36 * the "original" string. This class is aware of the escape quote, two quotes in sequence the respresent a single quote.
37 *
38 * @author Richard van Nieuwenhoven
39 *
40 * @deprecated (<i>for internal use</i>) Was used by {@link FitsLineAppender} only.
41 */
42 @Deprecated
43 public class FitsSubString {
44
45 /**
46 * the length of the substring (starting at the offset).
47 */
48 private int length;
49
50 /**
51 * the offset into the original string where this string starts.
52 */
53 private int offset;
54
55 /**
56 * the original String.
57 */
58 private final String originalString;
59
60 /**
61 * constructor for the substring, start by representing the whole string.
62 *
63 * @param originalString the string to represent.
64 */
65 @Deprecated
66 public FitsSubString(String originalString) {
67 this.originalString = originalString == null ? "" : originalString;
68 offset = 0;
69 length = this.originalString.length();
70 }
71
72 /**
73 * append the current string representation to the StringBuffer.
74 *
75 * @param buffer the buffer to append to.
76 */
77 @Deprecated
78 public void appendTo(StringBuilder buffer) {
79 buffer.append(originalString, offset, offset + length);
80 }
81
82 /**
83 * get the character at the specified position.
84 *
85 * @param pos the position the get the character from
86 *
87 * @return the character at the specified position
88 */
89 @Deprecated
90 public char charAt(int pos) {
91 return originalString.charAt(pos + offset);
92 }
93
94 /**
95 * Returns the number of characters in the original string, counted from the start position of this substring.
96 *
97 * @return get the length of the orginal string from the current offset.
98 */
99 @Deprecated
100 public int fullLength() {
101 return originalString.length() - offset;
102 }
103
104 /**
105 * check the string and set it to the maximum length specified. if a escaped quote is on the boundary the length is
106 * reduced in a way that the string does not separate an escape quote.
107 *
108 * @param max the maximum string legth to set.
109 */
110 @Deprecated
111 public void getAdjustedLength(int max) {
112 if (max <= 0) {
113 length = 0;
114 } else if (length > max) {
115 int pos = max - 1;
116 while (charAt(pos) == '\'') {
117 pos--;
118 }
119 // now we are at the start of the quotes step forward in steps of 2
120 pos += (max - 1 - pos) / 2 * 2;
121 length = pos + 1;
122 }
123 }
124
125 /**
126 * Returns the length of this substring.
127 *
128 * @return the string length of this String.
129 */
130 @Deprecated
131 public int length() {
132 return length;
133 }
134
135 /**
136 * shift the sting to the rest of the string, the part of the original string that is after the part of the string
137 * this instance currently represents.
138 */
139 @Deprecated
140 public void rest() {
141 offset += length;
142 length = originalString.length() - offset;
143 }
144
145 /**
146 * skip over the specified number of characters.
147 *
148 * @param count the number of chars to skip
149 */
150 @Deprecated
151 public void skip(int count) {
152 offset += count;
153 length -= count;
154 }
155
156 /**
157 * Checks if this substring contains the specified sequence.
158 *
159 * @param string the string to check
160 *
161 * @return true if the current string starts with the specified string.
162 */
163 @Deprecated
164 public boolean startsWith(String string) {
165 return originalString.regionMatches(offset, string, 0, string.length());
166 }
167 }