mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GT-2824 - Comments - fixed infinite loop when editing comments
This commit is contained in:
parent
8f9a8dd1b1
commit
d33ffc2855
17 changed files with 853 additions and 516 deletions
|
@ -1,105 +0,0 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Container object that holds a start and end position within a string.
|
||||
* A list of StringDiffs is used to keep track of changes made to a string.
|
||||
*
|
||||
*/
|
||||
public class StringDiff {
|
||||
/**
|
||||
* Start position of the string.
|
||||
*/
|
||||
public int pos1;
|
||||
/**
|
||||
* End position of the string used when part of the string is replaced.
|
||||
*/
|
||||
public int pos2;
|
||||
/**
|
||||
* String being inserted.
|
||||
*/
|
||||
public String insertData;
|
||||
|
||||
/**
|
||||
* Construct a new StringDiff with pos1 and pos2 are initialized to -1.
|
||||
* @param replaceData string
|
||||
*/
|
||||
public StringDiff(String replaceData) {
|
||||
pos1 = -1;
|
||||
pos2 = -1;
|
||||
insertData = replaceData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new StringDiff that indicates text was deleted from
|
||||
* pos1 to pos2.
|
||||
* @param pos1 position 1 for the diff
|
||||
* @param pos2 position 2 for the diff
|
||||
*/
|
||||
public StringDiff(int pos1, int pos2) {
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new StringDiff that indicates that insertData was
|
||||
* inserted at pos.
|
||||
* @param pos position where the insertData was inserted
|
||||
* @param insertData inserted string
|
||||
*/
|
||||
public StringDiff(int pos, String insertData) {
|
||||
this.pos1 = pos;
|
||||
this.insertData = insertData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new StringDiff that indicates given data is inserted
|
||||
* from pos1 to pos2.
|
||||
* @param pos1 position 1
|
||||
* @param pos2 position 2
|
||||
* @param data data the replaces string data
|
||||
*/
|
||||
public StringDiff(int pos1, int pos2, String data) {
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
insertData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof StringDiff) {
|
||||
StringDiff other = (StringDiff) obj;
|
||||
return pos1 == other.pos1 && pos2 == other.pos2 &&
|
||||
StringUtils.equals(insertData, other.insertData);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (insertData != null) {
|
||||
if (pos1 >= 0) {
|
||||
return "StringDiff: inserted <" + insertData + "> at " + pos1;
|
||||
}
|
||||
|
||||
return "StringDiff: replace with <" + insertData + ">";
|
||||
}
|
||||
return "StringDiff: deleted text from " + pos1 + " to " + pos2;
|
||||
}
|
||||
}
|
|
@ -138,7 +138,9 @@ public class StringUtilities {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns true if the character is displayable.
|
||||
* Returns true if the character is in displayable character range
|
||||
* @param c the character
|
||||
* @return true if the character is in displayable character range
|
||||
*/
|
||||
public static boolean isDisplayable(int c) {
|
||||
return c >= 0x20 && c < 0x7F;
|
||||
|
@ -547,33 +549,6 @@ public class StringUtilities {
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string array to single string with new line chars.
|
||||
*/
|
||||
public static String convertStringArray(String[] strings) {
|
||||
return convertStringArray(strings, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string array to single string with the given delimiter.
|
||||
*/
|
||||
public static String convertStringArray(String[] strings, String delimiter) {
|
||||
if (strings == null || strings.length == 0) {
|
||||
return null;
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
if (strings[i] == null) {
|
||||
continue;
|
||||
}
|
||||
sb.append(strings[i]);
|
||||
if (i < strings.length - 1) {
|
||||
sb.append(delimiter);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string containing multiple lines into an array where each
|
||||
* element in the array contains only a single line. The "\n" character is
|
||||
|
@ -638,6 +613,7 @@ public class StringUtilities {
|
|||
* @param source the original string to pad.
|
||||
* @param filler the type of characters with which to pad
|
||||
* @param length the length of padding to add (0 results in no changes)
|
||||
* @return the padded string
|
||||
* @deprecated use {@link #pad(String, char, int)}; functionally the same, but smaller
|
||||
* and more consistent name
|
||||
*/
|
||||
|
@ -654,6 +630,7 @@ public class StringUtilities {
|
|||
* @param source the original string to pad.
|
||||
* @param filler the type of characters with which to pad
|
||||
* @param length the length of padding to add (0 results in no changes)
|
||||
* @return the padded string
|
||||
*/
|
||||
public static String pad(String source, char filler, int length) {
|
||||
|
||||
|
@ -690,6 +667,7 @@ public class StringUtilities {
|
|||
* This is useful for constructing complicated <code>toString()</code> representations.
|
||||
*
|
||||
* @param s the input string
|
||||
* @param indent the indent string; this will be appended as needed
|
||||
* @return the output string
|
||||
*/
|
||||
public static String indentLines(String s, String indent) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue