Update Tesseract to version 4.
This commit is contained in:
56 files changed
+10765
-3462
No files matched your search
@@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: strngs.h (Formerly strings.h)
|
||||
* Description: STRING class definition.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Feb 15 09:15:01 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Feb 15 09:15:01 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,13 +17,18 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef STRNGS_H
|
||||
#define STRNGS_H
|
||||
#ifndef STRNGS_H
|
||||
#define STRNGS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "platform.h"
|
||||
#include "memry.h"
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for uint32_t
|
||||
#include <cstdio> // for FILE
|
||||
#include <cstring> // for strncpy
|
||||
#include "platform.h" // for TESS_API
|
||||
|
||||
namespace tesseract {
|
||||
class TFile;
|
||||
} // namespace tesseract.
|
||||
|
||||
// STRING_IS_PROTECTED means that string[index] = X is invalid
|
||||
// because you have to go through strings interface to modify it.
|
||||
@@ -43,38 +48,53 @@ class TESS_API STRING
|
||||
STRING();
|
||||
STRING(const STRING &string);
|
||||
STRING(const char *string);
|
||||
~STRING ();
|
||||
STRING(const char *data, int length);
|
||||
~STRING();
|
||||
|
||||
// Writes to the given file. Returns false in case of error.
|
||||
bool Serialize(FILE* fp) const;
|
||||
// Reads from the given file. Returns false in case of error.
|
||||
// If swap is true, assumes a big/little-endian swap is needed.
|
||||
bool DeSerialize(bool swap, FILE* fp);
|
||||
// Writes to the given file. Returns false in case of error.
|
||||
bool Serialize(tesseract::TFile* fp) const;
|
||||
// Reads from the given file. Returns false in case of error.
|
||||
// If swap is true, assumes a big/little-endian swap is needed.
|
||||
bool DeSerialize(tesseract::TFile* fp);
|
||||
// As DeSerialize, but only seeks past the data - hence a static method.
|
||||
static bool SkipDeSerialize(tesseract::TFile* fp);
|
||||
|
||||
BOOL8 contains(const char c) const;
|
||||
inT32 length() const;
|
||||
inT32 size() const { return length(); }
|
||||
bool contains(const char c) const;
|
||||
int32_t length() const;
|
||||
int32_t size() const { return length(); }
|
||||
// Workaround to avoid g++ -Wsign-compare warnings.
|
||||
uint32_t unsigned_size() const {
|
||||
const int32_t len = length();
|
||||
assert(0 <= len);
|
||||
return static_cast<uint32_t>(len);
|
||||
}
|
||||
const char *string() const;
|
||||
const char *c_str() const;
|
||||
|
||||
inline char* strdup() const {
|
||||
inT32 len = length() + 1;
|
||||
int32_t len = length() + 1;
|
||||
return strncpy(new char[len], GetCStr(), len);
|
||||
}
|
||||
|
||||
#if STRING_IS_PROTECTED
|
||||
const char &operator[] (inT32 index) const;
|
||||
const char &operator[] (int32_t index) const;
|
||||
// len is number of chars in s to insert starting at index in this string
|
||||
void insert_range(inT32 index, const char*s, int len);
|
||||
void erase_range(inT32 index, int len);
|
||||
void insert_range(int32_t index, const char*s, int len);
|
||||
void erase_range(int32_t index, int len);
|
||||
#else
|
||||
char &operator[] (inT32 index) const;
|
||||
char &operator[] (int32_t index) const;
|
||||
#endif
|
||||
void split(const char c, GenericVector<STRING> *splited);
|
||||
void truncate_at(inT32 index);
|
||||
void truncate_at(int32_t index);
|
||||
|
||||
BOOL8 operator== (const STRING & string) const;
|
||||
BOOL8 operator!= (const STRING & string) const;
|
||||
BOOL8 operator!= (const char *string) const;
|
||||
bool operator== (const STRING & string) const;
|
||||
bool operator!= (const STRING & string) const;
|
||||
bool operator!= (const char *string) const;
|
||||
|
||||
STRING & operator= (const char *string);
|
||||
STRING & operator= (const STRING & string);
|
||||
@@ -94,9 +114,11 @@ class TESS_API STRING
|
||||
// be ambiguous, and ints usually need a string before or between them
|
||||
// anyway.
|
||||
void add_str_int(const char* str, int number);
|
||||
// Appends the given string and double (as a %.8g) to this.
|
||||
void add_str_double(const char* str, double number);
|
||||
|
||||
// ensure capcaity but keep pointer encapsulated
|
||||
inline void ensure(inT32 min_capacity) { ensure_cstr(min_capacity); }
|
||||
// ensure capacity but keep pointer encapsulated
|
||||
inline void ensure(int32_t min_capacity) { ensure_cstr(min_capacity); }
|
||||
|
||||
private:
|
||||
typedef struct STRING_HEADER {
|
||||
@@ -106,9 +128,9 @@ class TESS_API STRING
|
||||
// used_ is how much of the capacity is currently being used,
|
||||
// including a '\0' terminator.
|
||||
//
|
||||
// If used_ is 0 then string is NULL (not even the '\0')
|
||||
// If used_ is 0 then string is nullptr (not even the '\0')
|
||||
// else if used_ > 0 then it is strlen() + 1 (because it includes '\0')
|
||||
// else strlen is >= 0 (not NULL) but needs to be computed.
|
||||
// else strlen is >= 0 (not nullptr) but needs to be computed.
|
||||
// this condition is set when encapsulation is violated because
|
||||
// an API returned a mutable string.
|
||||
//
|
||||
@@ -132,17 +154,15 @@ class TESS_API STRING
|
||||
}
|
||||
|
||||
// returns the string data part of storage
|
||||
inline char* GetCStr() {
|
||||
return ((char *)data_) + sizeof(STRING_HEADER);
|
||||
};
|
||||
inline char* GetCStr() { return ((char*)data_) + sizeof(STRING_HEADER); }
|
||||
|
||||
inline const char* GetCStr() const {
|
||||
return ((const char *)data_) + sizeof(STRING_HEADER);
|
||||
};
|
||||
}
|
||||
inline bool InvariantOk() const {
|
||||
#if STRING_IS_PROTECTED
|
||||
return (GetHeader()->used_ == 0) ?
|
||||
(string() == NULL) : (GetHeader()->used_ == (strlen(string()) + 1));
|
||||
(string() == nullptr) : (GetHeader()->used_ == (strlen(string()) + 1));
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
@@ -151,7 +171,7 @@ class TESS_API STRING
|
||||
// Ensure string has requested capacity as optimization
|
||||
// to avoid unnecessary reallocations.
|
||||
// The return value is a cstr buffer with at least requested capacity
|
||||
char* ensure_cstr(inT32 min_capacity);
|
||||
char* ensure_cstr(int32_t min_capacity);
|
||||
|
||||
void FixHeader() const; // make used_ non-negative, even if const
|
||||
|
||||
|
||||
Reference in new issue
Block a user