mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Simplify some string operations
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849760 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
accfb5a678
commit
f6eab84243
@ -72,7 +72,7 @@ public class FromHowTo {
|
||||
InputSource sheetSource = new InputSource(sheet);
|
||||
parser.parse(sheetSource);
|
||||
}
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
|
||||
sb.append(HexDump.shortToHex(_d3).substring(PREFIX_LEN));
|
||||
sb.append("-");
|
||||
String d4Chars = HexDump.longToHex(getD4());
|
||||
sb.append(d4Chars.substring(PREFIX_LEN, PREFIX_LEN+4));
|
||||
sb.append(d4Chars, PREFIX_LEN, PREFIX_LEN+4);
|
||||
sb.append("-");
|
||||
sb.append(d4Chars.substring(PREFIX_LEN+4));
|
||||
return sb.toString();
|
||||
|
||||
@ -38,7 +38,7 @@ public class VBAMacroExtractor {
|
||||
if (args.length == 0) {
|
||||
System.err.println("Use:");
|
||||
System.err.println(" VBAMacroExtractor <office.doc> [output]");
|
||||
System.err.println("");
|
||||
System.err.println();
|
||||
System.err.println("If an output directory is given, macros are written there");
|
||||
System.err.println("Otherwise they are output to the screen");
|
||||
System.exit(1);
|
||||
@ -90,7 +90,7 @@ public class VBAMacroExtractor {
|
||||
if (outputDir == null) {
|
||||
System.out.println(divider);
|
||||
System.out.println(moduleName);
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println(moduleCode);
|
||||
} else {
|
||||
File out = new File(outputDir, moduleName + extension);
|
||||
|
||||
@ -104,7 +104,7 @@ public class Dec2Bin extends Var1or2ArgFunction implements FreeRefFunction {
|
||||
String binary = Integer.toBinaryString(number.intValue());
|
||||
|
||||
if (binary.length() > DEFAULT_PLACES_VALUE) {
|
||||
binary = binary.substring(binary.length() - DEFAULT_PLACES_VALUE, binary.length());
|
||||
binary = binary.substring(binary.length() - DEFAULT_PLACES_VALUE);
|
||||
}
|
||||
//If DEC2BIN requires more than places characters, it returns the #NUM! error value.
|
||||
if (binary.length() > placesNumber) {
|
||||
|
||||
@ -75,7 +75,7 @@ public final class Substitute extends Var3or4ArgFunction {
|
||||
return sb.toString();
|
||||
}
|
||||
// store everything from end of last match to start of this match
|
||||
sb.append(oldStr.substring(startIndex, nextMatch));
|
||||
sb.append(oldStr, startIndex, nextMatch);
|
||||
sb.append(newStr);
|
||||
startIndex = nextMatch + searchStr.length();
|
||||
}
|
||||
@ -97,7 +97,7 @@ public final class Substitute extends Var3or4ArgFunction {
|
||||
count++;
|
||||
if (count == instanceNumber) {
|
||||
StringBuffer sb = new StringBuffer(oldStr.length() + newStr.length());
|
||||
sb.append(oldStr.substring(0, nextMatch));
|
||||
sb.append(oldStr, 0, nextMatch);
|
||||
sb.append(newStr);
|
||||
sb.append(oldStr.substring(nextMatch + searchStr.length()));
|
||||
return sb.toString();
|
||||
|
||||
@ -145,20 +145,20 @@ public class DataFormatter implements Observer {
|
||||
* Magenta, Red, White, Yellow, "Color n" (1<=n<=56)
|
||||
*/
|
||||
private static final Pattern colorPattern =
|
||||
Pattern.compile("(\\[BLACK\\])|(\\[BLUE\\])|(\\[CYAN\\])|(\\[GREEN\\])|" +
|
||||
"(\\[MAGENTA\\])|(\\[RED\\])|(\\[WHITE\\])|(\\[YELLOW\\])|" +
|
||||
"(\\[COLOR\\s*\\d\\])|(\\[COLOR\\s*[0-5]\\d\\])", Pattern.CASE_INSENSITIVE);
|
||||
Pattern.compile("(\\[BLACK])|(\\[BLUE])|(\\[CYAN])|(\\[GREEN])|" +
|
||||
"(\\[MAGENTA])|(\\[RED])|(\\[WHITE])|(\\[YELLOW])|" +
|
||||
"(\\[COLOR\\s*\\d])|(\\[COLOR\\s*[0-5]\\d])", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/**
|
||||
* A regex to identify a fraction pattern.
|
||||
* This requires that replaceAll("\\?", "#") has already been called
|
||||
*/
|
||||
private static final Pattern fractionPattern = Pattern.compile("(?:([#\\d]+)\\s+)?(#+)\\s*\\/\\s*([#\\d]+)");
|
||||
private static final Pattern fractionPattern = Pattern.compile("(?:([#\\d]+)\\s+)?(#+)\\s*/\\s*([#\\d]+)");
|
||||
|
||||
/**
|
||||
* A regex to strip junk out of fraction formats
|
||||
*/
|
||||
private static final Pattern fractionStripper = Pattern.compile("(\"[^\"]*\")|([^ \\?#\\d\\/]+)");
|
||||
private static final Pattern fractionStripper = Pattern.compile("(\"[^\"]*\")|([^ ?#\\d/]+)");
|
||||
|
||||
/**
|
||||
* A regex to detect if an alternate grouping character is used
|
||||
@ -413,7 +413,7 @@ public class DataFormatter implements Observer {
|
||||
if (symbol.indexOf('$') > -1) {
|
||||
symbol = symbol.substring(0, symbol.indexOf('$')) +
|
||||
'\\' +
|
||||
symbol.substring(symbol.indexOf('$'), symbol.length());
|
||||
symbol.substring(symbol.indexOf('$'));
|
||||
}
|
||||
formatStr = m.replaceAll(symbol);
|
||||
m = localePatternGroup.matcher(formatStr);
|
||||
|
||||
@ -349,9 +349,7 @@ public final class PackagingURIHelper {
|
||||
// "/ppt/slides/slide1.xml" and the targetURI is "slide1.xml" then
|
||||
// this it should be relativized as "slide1.xml", i.e. the last segment.
|
||||
retVal.append(segmentsSource[segmentsSource.length - 1]);
|
||||
} else {
|
||||
retVal.append("");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Matched for so long, but no more
|
||||
|
||||
@ -508,7 +508,7 @@ public class XSSFRichTextString implements RichTextString {
|
||||
while(m.find()) {
|
||||
int pos = m.start();
|
||||
if( pos > idx) {
|
||||
buf.append(value.substring(idx, pos));
|
||||
buf.append(value, idx, pos);
|
||||
}
|
||||
|
||||
String code = m.group(1);
|
||||
|
||||
@ -1569,7 +1569,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
||||
if ((j == textEnd) && (i == runEnd)) {
|
||||
endChar = charEnd;
|
||||
}
|
||||
out.append(tmpText.substring(startChar, endChar + 1));
|
||||
out.append(tmpText, startChar, endChar + 1);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
|
||||
@ -45,8 +45,8 @@ public final class HMEFContentsExtractor {
|
||||
if(args.length < 2) {
|
||||
System.err.println("Use:");
|
||||
System.err.println(" HMEFContentsExtractor <filename> <output dir>");
|
||||
System.err.println("");
|
||||
System.err.println("");
|
||||
System.err.println();
|
||||
System.err.println();
|
||||
System.err.println("Where <filename> is the winmail.dat file to extract,");
|
||||
System.err.println(" and <output dir> is where to place the extracted files");
|
||||
System.exit(2);
|
||||
|
||||
@ -124,14 +124,14 @@ public final class HPBFDumper {
|
||||
}
|
||||
protected void dumpEscherStm(DirectoryNode escherDir) throws IOException {
|
||||
byte[] data = getData(escherDir, "EscherStm");
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("EscherStm - " + data.length + " bytes long:");
|
||||
if(data.length > 0)
|
||||
dumpEscherStream(data);
|
||||
}
|
||||
protected void dumpEscherDelayStm(DirectoryNode escherDir) throws IOException {
|
||||
byte[] data = getData(escherDir, "EscherDelayStm");
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("EscherDelayStm - " + data.length + " bytes long:");
|
||||
if(data.length > 0)
|
||||
dumpEscherStream(data);
|
||||
@ -140,14 +140,14 @@ public final class HPBFDumper {
|
||||
public void dumpEnvelope() throws IOException {
|
||||
byte[] data = getData(fs.getRoot(), "Envelope");
|
||||
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("Envelope - " + data.length + " bytes long:");
|
||||
}
|
||||
|
||||
public void dumpContents() throws IOException {
|
||||
byte[] data = getData(fs.getRoot(), "Contents");
|
||||
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("Contents - " + data.length + " bytes long:");
|
||||
|
||||
// 8 bytes, always seems to be
|
||||
@ -179,7 +179,7 @@ public final class HPBFDumper {
|
||||
public void dumpCONTENTSraw(DirectoryNode dir) throws IOException {
|
||||
byte[] data = getData(dir, "CONTENTS");
|
||||
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("CONTENTS - " + data.length + " bytes long:");
|
||||
|
||||
// Between the start and 0x200 we have
|
||||
@ -236,7 +236,7 @@ public final class HPBFDumper {
|
||||
}
|
||||
if(textStop > 0) {
|
||||
int len = (textStop - 0x200) / 2;
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println(
|
||||
StringUtil.getFromUnicodeLE(data, 0x200, len)
|
||||
);
|
||||
@ -250,7 +250,7 @@ public final class HPBFDumper {
|
||||
public void dumpCONTENTSguessed(DirectoryNode dir) throws IOException {
|
||||
byte[] data = getData(dir, "CONTENTS");
|
||||
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("CONTENTS - " + data.length + " bytes long:");
|
||||
|
||||
String[] startType = new String[20];
|
||||
@ -313,10 +313,10 @@ public final class HPBFDumper {
|
||||
}
|
||||
|
||||
// Text
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("TEXT:");
|
||||
System.out.println(text);
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
|
||||
// All the others
|
||||
for(int i=0; i<20; i++) {
|
||||
|
||||
@ -73,7 +73,7 @@ public final class PLCDumper {
|
||||
}
|
||||
|
||||
private void dumpBit(QCBit bit, int index) {
|
||||
System.out.println("");
|
||||
System.out.println();
|
||||
System.out.println("Dumping " + bit.getBitType() + " bit at " + index);
|
||||
System.out.println(" Is a " + bit.getThingType() + ", number is " + bit.getOptA());
|
||||
System.out.println(" Starts at " + bit.getDataOffset() + " (0x" + Integer.toHexString(bit.getDataOffset()) + ")");
|
||||
|
||||
@ -90,11 +90,8 @@ public final class WordExtractor extends POIOLE2TextExtractor {
|
||||
|
||||
// Process the first argument as a file
|
||||
InputStream fin = new FileInputStream( args[0] );
|
||||
WordExtractor extractor = new WordExtractor( fin );
|
||||
try {
|
||||
System.out.println( extractor.getText() );
|
||||
} finally {
|
||||
extractor.close();
|
||||
try (WordExtractor extractor = new WordExtractor(fin)) {
|
||||
System.out.println(extractor.getText());
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +172,7 @@ public final class WordExtractor extends POIOLE2TextExtractor {
|
||||
}
|
||||
if ( text.endsWith( "\n\n" ))
|
||||
{
|
||||
out.append( text.substring( 0, text.length() - 1 ));
|
||||
out.append(text, 0, text.length() - 1);
|
||||
return;
|
||||
}
|
||||
out.append( text );
|
||||
|
||||
@ -98,7 +98,7 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
||||
+ "make the fix elsewhere (do not modify this test or the proof spreadsheet to get the test working).");
|
||||
ps.println("If the changes were wanted, make sure to open the newly generated file in Excel "
|
||||
+ "and verify it manually. The new proof file should be submitted after it is verified to be correct.");
|
||||
ps.println("");
|
||||
ps.println();
|
||||
ps.println("One other possible (but less likely) cause of a failed test is a problem in the "
|
||||
+ "comparison logic used here. Perhaps some extra file regions need to be ignored.");
|
||||
ps.println("The generated file has been saved to '" + generatedFile.getAbsolutePath() + "' for manual inspection.");
|
||||
|
||||
@ -514,7 +514,7 @@ public final class ExcelFileFormatDocFunctionExtractor {
|
||||
ps.println(" (size=" + effDocFile.length() + ", md5=" + getFileMD5(effDocFile) + ")");
|
||||
ps.println("#");
|
||||
ps.println("#Columns: (index, name, minParams, maxParams, returnClass, paramClasses, isVolatile, hasFootnote )");
|
||||
ps.println("");
|
||||
ps.println();
|
||||
try {
|
||||
// can't use ZipHelper here, because its in a different module
|
||||
ZipFile zf = new ZipFile(effDocFile);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user