MCPcopy Create free account
hub / github.com/BombusMod/BombusMod / parseMessage

Method parseMessage

src/main/java/util/StringUtils.java:126–167  ·  view source on GitHub ↗
(String value, int availWidth, Font font)

Source from the content-addressed store, hash-verified

124 }
125
126 public static Vector parseMessage(String value, int availWidth, Font font) {
127 StringBuffer out=new StringBuffer(value);
128
129 value = Msg.clearNick(out);
130
131 Vector lines=new Vector();
132 char[] valueChars = value.toCharArray();
133 int startPos = 0;
134 int lastSpacePos = -1;
135 int lastSpacePosLength = 0;
136 int currentLineWidth = 0;
137 for (int i = 0; i < valueChars.length; i++) {
138 char c = valueChars[i];
139 currentLineWidth += font.charWidth( c );
140 if (c == '\n') {
141 lines.addElement( new String( valueChars, startPos, i - startPos ) );
142 lastSpacePos = -1;
143 startPos = i+1;
144 currentLineWidth = 0;
145 i = startPos;
146 } else if (currentLineWidth >= availWidth && i > 0) {
147 if ( lastSpacePos == -1 ) {
148 i--;
149 lines.addElement( new String( valueChars, startPos, i - startPos ) );
150 startPos = i;
151 currentLineWidth = 0;
152 } else {
153 currentLineWidth -= lastSpacePosLength;
154 lines.addElement( new String( valueChars, startPos, lastSpacePos - startPos ) );
155 startPos = lastSpacePos + 1;
156 lastSpacePos = -1;
157 }
158 } else if (c == ' ' || c == '\t') {
159 lastSpacePos = i;
160 lastSpacePosLength = currentLineWidth;
161 }
162 }
163 // last string
164 lines.addElement( new String( valueChars, startPos, valueChars.length - startPos ) );
165
166 return lines;
167 }
168
169 public static String toExtendedString(String src){
170 src=stringReplace(src,"%dt",Time.dispLocalTime());

Callers 2

addPopupMethod · 0.95
getVHeightMethod · 0.95

Calls 3

clearNickMethod · 0.95
addElementMethod · 0.80
charWidthMethod · 0.65

Tested by

no test coverage detected