added missing methods

This commit is contained in:
Eism 2019-07-17 19:17:18 +02:00
parent 635cfab83c
commit 0cd99217df
5 changed files with 36 additions and 3 deletions

View File

@ -43,8 +43,8 @@ int String::size() const { return int(text_.size()); }
int String::length() const { return int(text_.size()); } int String::length() const { return int(text_.size()); }
Ref<String> String::substring(int i) const { Ref<String> String::substring(int i, int j) const {
return Ref<String>(new String(text_.substr(i))); return Ref<String>(new String(text_.substr(i, j)));
} }
void String::append(const std::string &tail) { void String::append(const std::string &tail) {

View File

@ -37,7 +37,7 @@ public:
explicit String(const std::string &text); explicit String(const std::string &text);
explicit String(int); explicit String(int);
char charAt(int) const; char charAt(int) const;
Ref<String> substring(int) const; Ref<String> substring(int, int = -1) const;
const std::string& getText() const; const std::string& getText() const;
int size() const; int size() const;
void append(std::string const& tail); void append(std::string const& tail);

View File

@ -18,6 +18,7 @@
*/ */
#include <cmath> #include <cmath>
#include <vector>
namespace zxing { namespace zxing {
namespace common { namespace common {
@ -48,6 +49,14 @@ class MathUtils {
int yDiff = aY - bY; int yDiff = aY - bY;
return sqrt(float(xDiff * xDiff + yDiff * yDiff)); return sqrt(float(xDiff * xDiff + yDiff * yDiff));
} }
static inline int sum(std::vector<int> array) {
int count = 0;
for (int a : array) {
count += a;
}
return count;
}
}; };
} }

View File

@ -221,4 +221,24 @@ void OneDReader::recordPattern(Ref<BitArray> row,
} }
} }
void OneDReader::recordPatternInReverse(Ref<BitArray> row,
int start,
vector<int>& counters)
{
// This could be more efficient I guess
int numTransitionsLeft = int(counters.size());
bool last = row->get(start);
while (start > 0 && numTransitionsLeft >= 0) {
if (row->get(--start) != last) {
numTransitionsLeft--;
last = !last;
}
}
if (numTransitionsLeft >= 0)
{
throw NotFoundException();
}
recordPattern(row, start + 1, counters);
}
OneDReader::~OneDReader() {} OneDReader::~OneDReader() {}

View File

@ -72,6 +72,10 @@ public:
static void recordPattern(Ref<BitArray> row, static void recordPattern(Ref<BitArray> row,
int start, int start,
std::vector<int>& counters); std::vector<int>& counters);
static void recordPatternInReverse(Ref<BitArray> row,
int start,
std::vector<int>& counters);
virtual ~OneDReader(); virtual ~OneDReader();
}; };