25 #ifndef TESSERACT_CCUTIL_HELPERS_H_
26 #define TESSERACT_CCUTIL_HELPERS_H_
33 int last_index = strlen(str) - 1;
34 while (last_index >= 0 &&
35 (str[last_index] ==
'\n' || str[last_index] ==
'\r')) {
36 str[last_index--] =
'\0';
42 if (fgetc(file) !=
'\n') fseek(file, -1, SEEK_CUR);
47 float diff = *((
float *) arg1) - *((
float *) arg2);
50 }
else if (diff < 0) {
58 inline int RoundUp(
int n,
int block_size) {
59 return block_size * ((n + block_size - 1) / block_size);
64 inline T
ClipToRange(
const T& x,
const T& lower_bound,
const T& upper_bound) {
73 template<
typename T1,
typename T2>
74 inline void UpdateRange(
const T1& x, T2* lower_bound, T2* upper_bound) {
82 template<
typename T1,
typename T2>
84 T2* lower_bound, T2* upper_bound) {
85 if (x_lo < *lower_bound)
87 if (x_hi > *upper_bound)
96 T* lower2, T* upper2) {
107 return (a % b + b) % b;
117 return a >= 0 ? (a + b / 2) / b : (a - b / 2) / b;
122 return x >= 0.0 ?
static_cast<int>(x + 0.5) : -
static_cast<int>(-x + 0.5);
127 char *cptr =
reinterpret_cast<char *
>(ptr);
128 int halfsize = num_bytes / 2;
129 for (
int i = 0; i < halfsize; ++i) {
131 cptr[i] = cptr[num_bytes - 1 - i];
132 cptr[num_bytes - 1 - i] = tmp;
152 #endif // TESSERACT_CCUTIL_HELPERS_H_