做代碼工具,需要對行進行計數或者判斷。WINDOWS/ LINUX 是不一樣的,怎樣正确處理?吾代碼如下:
private int isLine(final int pos)
{
// WINDOWS換行
if (textBuffer[pos] == '\r')
{
return (textBuffer[pos+1] == '\n') ? 2 : 1;
}
// LINUX換行
if (textBuffer[pos] == '\n')
{
//避免重複計數。
if (pos > 0 && textBuffer[pos-1] == '\r')
{
return 0;
}
return 1;
}
return 0;
}