Here you can find the source of lengthExpandedTabs(String string, int toIdx, int tabWidth)
Parameter | Description |
---|---|
string | the input String |
toIdx | index in string (exclusive) where the calculation stops |
tabWidth | the distance between tab stop position. |
public static int lengthExpandedTabs(String string, int toIdx, int tabWidth)
//package com.java2s; // License as published by the Free Software Foundation; either public class Main { /**//from w w w . ja v a 2s . c o m * Returns the length of a String prefix with tabs expanded. * Each tab is counted as the number of characters is takes to * jump to the next tab stop. * @param string the input String * @param toIdx index in string (exclusive) where the calculation stops * @param tabWidth the distance between tab stop position. * @return the length of string.substring(0, toIdx) with tabs expanded. */ public static int lengthExpandedTabs(String string, int toIdx, int tabWidth) { int len = 0; for (int idx = 0; idx < toIdx; idx++) { if (string.charAt(idx) == '\t') { len = (len / tabWidth + 1) * tabWidth; } else { len++; } } return len; } }