ISO8601d: Added ::length and tests
This commit is contained in:
@@ -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 ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user