Skip to content

Commit

Permalink
Improve wrap line rule to respect inline newline symbol.
Browse files Browse the repository at this point in the history
  • Loading branch information
Muyangmin committed Sep 8, 2016
1 parent 3f54be4 commit 115e858
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions plog/src/main/java/org/mym/plog/PLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,25 @@ else if (TextUtils.isEmpty(tag)) {
StringBuilder sb = new StringBuilder(logContent.length()
+ logContent.length() / maxLengthPerLine); //plus \n symbol
while (currentIndex < logContent.length()) {
//substring, if still over one line, preserve for next line
//compute max length of this line
int currentLineLength = Math.min(mConfig.getMaxLengthPerLine(),
logContent.length() - currentIndex);
String subLine = logContent.substring(currentIndex, currentIndex +
currentLineLength);

//move cursor
currentIndex += currentLineLength;
//Force new line if \n appears, otherwise use our soft wrap.
String subLine;

int newlineIndex = logContent.indexOf("\n", currentIndex);
int thisLineEnd = currentIndex + currentLineLength;

//has \n in this line;
if (newlineIndex != -1 && newlineIndex < thisLineEnd){
subLine = logContent.substring(currentIndex, newlineIndex);
currentIndex = newlineIndex + 1;
}
else{
subLine = logContent.substring(currentIndex, thisLineEnd);
currentIndex = thisLineEnd;
}

//Not print yet, only append.
sb.append(subLine).append("\n");
Expand Down

0 comments on commit 115e858

Please sign in to comment.