forked from edukaj/fontdef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodepoint.cpp
More file actions
30 lines (24 loc) · 762 Bytes
/
codepoint.cpp
File metadata and controls
30 lines (24 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "codepoint.h"
#include <iostream>
using namespace std;
bool operator ==(const CodePointRange& lhs, const CodePointRange& rhs)
{
return (lhs.first() == rhs.first()) && (lhs.last() != rhs.last());
}
ostream& operator << (ostream& os, const CodePointRange& cp)
{
os << cp.first() << '-' << cp.last();
return os;
}
istream& operator >> (istream& is, CodePointRange& cp)
{
std::string toParse;
is >> toParse;
auto separatorPos = toParse.find_first_of('-');
if (separatorPos == std::string::npos)
throw std::invalid_argument{"unable to parse code points"};
auto firstNumber = std::stoi(toParse.substr(0, separatorPos));
auto secondNumber = std::stoi(toParse.substr(separatorPos + 1));
cp.first(firstNumber).last(secondNumber);
return is;
}