1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 | package Torello.Java;
import java.util.stream.Stream;
import java.io.IOException;
class SingleLineRegExMatch_ONE_FILE
{
static InternalSED.ResultsSED handleOneFile(
final String fileName,
final FileNode file,
final String fileAsStr,
final CONFIG_RECORD userConfig
)
throws IOException
{
// Split into Lines As java.lang.String
final String[] lines = fileAsStr.split("\n");
// This is used for a minor optimization.
final SingleLineRegExMatch_ONE_LINE.LoopHelper loopHelper =
new SingleLineRegExMatch_ONE_LINE.LoopHelper(userConfig);
// Iterate each line of the file.
for (int curLineNum=0; curLineNum < lines.length; curLineNum++)
SingleLineRegExMatch_ONE_LINE
.handleOneLine(lines[curLineNum], curLineNum, loopHelper);
// If no changes occured, then there is just nothing to do
if (loopHelper.matchCount == 0) return InternalSED.NO_CHANGES_RET;
// All Printing-Records, from a Sream.Builder into an Array
final PrintingRecSingleLine[] PRSLA =
loopHelper.PRSLB.build().toArray(PrintingRecSingleLine[]::new);
// unless Verbosity.Silent was requested, print the matches.
if (userConfig.verbosity.level > 0) PrintingRecSingleLine.printAll
(PRSLA, userConfig.useUNIXColors, userConfig.appendable, userConfig.verbosity);
// Query the User about his or her feelings (after showing the matches)
if (userConfig.askFirst) if (! Q.YN("Re-Write the Updated File to Disk?"))
return InternalSED.NO_CHANGES_RET;
// The updated file was constructed inside the LoopHelper's 'newFileSB' StringBuilder
return new InternalSED.ResultsSED(loopHelper.newFileSB.toString(), loopHelper.matchCount);
}
}
|