mirror of https://gitee.com/cxasm/notepad--.git
25 lines
526 B
C++
25 lines
526 B
C++
|
#include "common.h"
|
||
|
|
||
|
|
||
|
int nbDigitsFromNbLines(size_t nbLines)
|
||
|
{
|
||
|
int nbDigits = 0; // minimum number of digit should be 4
|
||
|
if (nbLines < 10) nbDigits = 1;
|
||
|
else if (nbLines < 100) nbDigits = 2;
|
||
|
else if (nbLines < 1000) nbDigits = 3;
|
||
|
else if (nbLines < 10000) nbDigits = 4;
|
||
|
else if (nbLines < 100000) nbDigits = 5;
|
||
|
else if (nbLines < 1000000) nbDigits = 6;
|
||
|
else // rare case
|
||
|
{
|
||
|
nbDigits = 7;
|
||
|
nbLines /= 1000000;
|
||
|
|
||
|
while (nbLines)
|
||
|
{
|
||
|
nbLines /= 10;
|
||
|
++nbDigits;
|
||
|
}
|
||
|
}
|
||
|
return nbDigits;
|
||
|
}
|