ISO8601d: Added ::length and tests

This commit is contained in:
Paul Beckingham 2015-09-26 13:38:32 -04:00
parent 9962c14de2
commit f615db8a4c
3 changed files with 65 additions and 1 deletions

View file

@ -31,6 +31,7 @@
#include <ISO8601.h>
#include <Date.h>
#include <text.h>
#include <utf8.h>
#include <i18n.h>
#define DAY 86400
@ -815,6 +816,43 @@ int ISO8601d::dayOfWeek (const std::string& input)
return -1;
}
////////////////////////////////////////////////////////////////////////////////
int ISO8601d::length (const std::string& format)
{
int len = 0;
for (auto& i : format)
{
switch (i)
{
case 'm':
case 'M':
case 'd':
case 'D':
case 'y':
case 'v':
case 'V':
case 'h':
case 'H':
case 'n':
case 'N':
case 's':
case 'S': len += 2; break;
case 'b':
case 'j':
case 'J':
case 'a': len += 3; break;
case 'Y': len += 4; break;
case 'A':
case 'B': len += 10; break;
// Calculate the width, don't assume a single character width.
default: len += mk_wcwidth (i); break;
}
}
return len;
}
////////////////////////////////////////////////////////////////////////////////
void ISO8601p::clear ()
{