Skip to content

Commit

Permalink
crengine: string code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Lopatin committed Apr 3, 2012
1 parent 015a306 commit 641e1c8
Show file tree
Hide file tree
Showing 27 changed files with 218 additions and 217 deletions.
2 changes: 1 addition & 1 deletion android/jni/cr3engine.cpp
Expand Up @@ -456,7 +456,7 @@ JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_Engine_initInternal
if ( !fontMan->RegisterFont( fontName ) )
CRLog::error("cannot load font %s", fontName.c_str());
}
CRLog::info("%d fonts registered", (int)fontMan->GetFontCount());
CRLog::info("%d fonts registered", fontMan->GetFontCount());
return fontMan->GetFontCount() ? JNI_TRUE : JNI_FALSE;
}

Expand Down
4 changes: 2 additions & 2 deletions cr3gui/src/cr3main.cpp
Expand Up @@ -162,7 +162,7 @@ bool getDirectoryFonts( lString16Collection & pathList, lString16Collection & ex
{
int foundCount = 0;
lString16 path;
for ( unsigned di=0; di<pathList.length();di++ ) {
for ( int di=0; di<pathList.length();di++ ) {
path = pathList[di];
LVContainerRef dir = LVOpenDirectory(path.c_str());
if ( !dir.isNull() ) {
Expand Down Expand Up @@ -269,7 +269,7 @@ bool InitCREngine( const char * exename, lString16Collection & fontDirs )
// load fonts from file
CRLog::debug("%d font files found", fonts.length());
//if (!fontMan->GetFontCount()) {
for ( unsigned fi=0; fi<fonts.length(); fi++ ) {
for ( int fi=0; fi<fonts.length(); fi++ ) {
lString8 fn = UnicodeToLocal(fonts[fi]);
CRLog::trace("loading font: %s", fn.c_str());
if ( !fontMan->RegisterFont(fn) ) {
Expand Down
2 changes: 1 addition & 1 deletion cr3gui/src/mainwnd.cpp
Expand Up @@ -824,7 +824,7 @@ VIEWER_MENU_4ABOUT=About...
CRGUIAcceleratorTableRef menuItems = _wm->getAccTables().get(lString16("mainMenuItems"));
if ( !menuItems.isNull() && menuItems->length()>1 ) {
// get menu from file
for ( unsigned i=0; i<menuItems->length(); i++ ) {
for ( int i=0; i<menuItems->length(); i++ ) {
const CRGUIAccelerator * acc = menuItems->get( i );
int cmd = acc->commandId;
int param = acc->commandParam;
Expand Down
4 changes: 2 additions & 2 deletions cr3gui/src/scrkbd.cpp
Expand Up @@ -44,9 +44,9 @@ bool CRScreenKeyboard::digitEntered( lChar16 c )
void CRScreenKeyboard::setLayout( CRKeyboardLayoutRef layout )
{
_keymap.clear();
unsigned maxcols = 0;
int maxcols = 0;
if ( !layout.isNull() ) {
for ( unsigned i=1; i<layout->vKeyboard->getItems().length(); i++ ) {
for ( int i=1; i<layout->vKeyboard->getItems().length(); i++ ) {
lString16 s = layout->vKeyboard->get( i );
if ( !s.empty() )
_keymap.add( s );
Expand Down
6 changes: 3 additions & 3 deletions cr3gui/src/t9encoding.h
Expand Up @@ -43,9 +43,9 @@ class TEncoding {
int encode(lChar16 ch) const
{
assert(keytable_.length() <= 10);
for (unsigned i = 0; i < keytable_.length(); i++) {
for (int i = 0; i < keytable_.length(); i++) {
const lString16& ref = keytable_[i];
for( unsigned j = 0; j < ref.length(); j ++ ) {
for( int j = 0; j < ref.length(); j ++ ) {
if (ref[j] == ch) {
return i;
}
Expand All @@ -59,7 +59,7 @@ class TEncoding {
{ // s not const, because we lower it here
s.lowercase();
lString8 result;
for (unsigned i = 0; i < s.length(); i ++) {
for (int i = 0; i < s.length(); i ++) {
result.append(1,static_cast<lChar8>('0'+encode(s[i])));
}
return result;
Expand Down
8 changes: 4 additions & 4 deletions cr3gui/src/tocdlg.cpp
Expand Up @@ -50,9 +50,9 @@ void CRTOCDialog::draw()
tocRect.shrinkBy(borders);
int curPage = _docview->getCurPage();
// draw toc
for ( int i=0; i<_pageItems && i+_topItem<(int)_items.length(); i++ ) {
for (int i=0; i < _pageItems && i + _topItem < _items.length(); i++) {
LVTocItem * item = _items[ i + _topItem];
LVTocItem * nextitem = (i+_topItem+1)<(int)_items.length()
LVTocItem * nextitem = (i+_topItem+1) < _items.length()
? _items[ i + _topItem + 1] : NULL;

//lvRect margins( 10, 10, 10, 10 );
Expand Down Expand Up @@ -144,7 +144,7 @@ CRTOCDialog::CRTOCDialog( CRGUIWindowManager * wm, lString16 title, int resultCm
int curItem = getCurItemIndex();
_topItem = curItem>=0 ? curItem / _pageItems * _pageItems : 0;
_page = _topItem / _pageItems + 1;
_pages = (_items.length()+(_pageItems-1))/ _pageItems;
_pages = (_items.length() + (_pageItems - 1)) / _pageItems;
int curPage = _docview->getCurPage();
int docPages = _docview->getPageCount();
lString16 pageString(_("Current page: $1 of $2\n"));
Expand Down Expand Up @@ -174,7 +174,7 @@ int CRTOCDialog::getCurItemIndex()
int curPage = _docview->getCurPage();
for ( int i=0; i<_items.length(); i++ ) {
LVTocItem * item = _items[ i ];
LVTocItem * nextitem = (i+1)<(int)_items.length()
LVTocItem * nextitem = (i+1) < _items.length()
? _items[ i + 1] : NULL;
bool isSelected = true;
if ( curPage < item->getPage() )
Expand Down
2 changes: 1 addition & 1 deletion cr3gui/src/viewdlg.cpp
Expand Up @@ -623,7 +623,7 @@ void CRViewDialog::showKeymapDialog()
lString8 txt;
txt << "<table><tr><th>";
txt << "<b>" << _("Key") << "</b></th><th><b>"<< _("Assigned function") <<"</b></th></tr>";
for ( unsigned i=0; i<_acceleratorTable->length(); i++ ) {
for ( int i=0; i<_acceleratorTable->length(); i++ ) {
const CRGUIAccelerator * acc = _acceleratorTable->get( i );
txt << "<tr><td>";
txt << getKeyName( acc->keyCode, acc->keyFlags );
Expand Down
2 changes: 1 addition & 1 deletion cr3qt/src/crqtutil.cpp
Expand Up @@ -121,7 +121,7 @@ PropsRef operator ^ ( PropsRef props1, PropsRef props2 )
void cr2qt( QStringList & dst, const lString16Collection & src )
{
dst.clear();
for ( unsigned i=0; i<src.length(); i++ ) {
for ( int i=0; i<src.length(); i++ ) {
dst.append( cr2qt( src[i] ) );
}
}
Expand Down
6 changes: 3 additions & 3 deletions cr3qt/src/main.cpp
Expand Up @@ -266,7 +266,7 @@ bool getDirectoryFonts( lString16Collection & pathList, lString16Collection & ex
{
int foundCount = 0;
lString16 path;
for ( unsigned di=0; di<pathList.length();di++ ) {
for ( int di=0; di<pathList.length();di++ ) {
path = pathList[di];
LVContainerRef dir = LVOpenDirectory(path.c_str());
if ( !dir.isNull() ) {
Expand All @@ -280,7 +280,7 @@ bool getDirectoryFonts( lString16Collection & pathList, lString16Collection & ex
bool found = false;
lString16 lc = fileName;
lc.lowercase();
for ( unsigned j=0; j<ext.length(); j++ ) {
for ( int j=0; j<ext.length(); j++ ) {
if ( lc.endsWith(ext[j]) ) {
found = true;
break;
Expand Down Expand Up @@ -409,7 +409,7 @@ bool InitCREngine( const char * exename, lString16Collection & fontDirs )
// load fonts from file
CRLog::debug("%d font files found", fonts.length());
//if (!fontMan->GetFontCount()) {
for ( unsigned fi=0; fi<fonts.length(); fi++ ) {
for ( int fi=0; fi<fonts.length(); fi++ ) {
lString8 fn = UnicodeToLocal(fonts[fi]);
CRLog::trace("loading font: %s", fn.c_str());
if ( !fontMan->RegisterFont(fn) ) {
Expand Down
6 changes: 3 additions & 3 deletions cr3qt/src/settings.cpp
Expand Up @@ -34,7 +34,7 @@ static void findImagesFromDirectory( lString16 dir, lString16Collection & files
}

static void findBackgrounds( lString16Collection & baseDirs, lString16Collection & files ) {
unsigned i;
int i;
for ( i=0; i<baseDirs.length(); i++ ) {
lString16 baseDir = baseDirs[i];
LVAppendPathDelimiter(baseDir);
Expand Down Expand Up @@ -104,7 +104,7 @@ SettingsDlg::SettingsDlg(QWidget *parent, CR3View * docView ) :
m_backgroundFiles.append("[NONE]");
bgFileLabels.append("[NONE]");
QString bgFile = m_props->getStringDef(PROP_BACKGROUND_IMAGE, "");
for ( unsigned i=0; i<bgFiles.length(); i++ ) {
for ( int i=0; i<bgFiles.length(); i++ ) {
lString16 fn = bgFiles[i];
QString f = cr2qt(fn);
if ( f==bgFile )
Expand Down Expand Up @@ -172,7 +172,7 @@ SettingsDlg::SettingsDlg(QWidget *parent, CR3View * docView ) :

int n = m_props->getIntDef( PROP_PAGE_MARGIN_LEFT, 8 );
int mi = 0;
for ( unsigned i=0; i<MAX_MARGIN_INDEX; i++ ) {
for ( int i=0; i<MAX_MARGIN_INDEX; i++ ) {
if ( n <= def_margins[i] ) {
mi = i;
break;
Expand Down
8 changes: 4 additions & 4 deletions cr3wx/src/cr3.cpp
Expand Up @@ -263,7 +263,7 @@ void testHyphen( const char * str )
HyphMan::hyphenate( s16.c_str(), s16.length(), widths, flags, 1, 15 );
lString8 buf( str );
buf << " = ";
for ( unsigned i=0; i<s16.length(); i++ ) {
for ( int i=0; i<s16.length(); i++ ) {
buf << str[i];
if ( flags[i] & LCHAR_ALLOW_HYPH_WRAP_AFTER )
buf << '-';
Expand Down Expand Up @@ -383,7 +383,7 @@ ResourceContainer * resources = NULL;

static lChar16 detectSlash( lString16 path )
{
for ( unsigned i=0; i<path.length(); i++ )
for ( int i=0; i<path.length(); i++ )
if ( path[i]=='\\' || path[i]=='/' )
return path[i];
#ifdef _WIN32
Expand Down Expand Up @@ -538,7 +538,7 @@ bool getDirectoryFonts( lString16Collection & pathList, lString16 ext, lString16
{
int foundCount = 0;
lString16 path;
for ( unsigned di=0; di<pathList.length();di++ ) {
for ( int di=0; di<pathList.length();di++ ) {
path = pathList[di];
LVContainerRef dir = LVOpenDirectory(path.c_str());
if ( !dir.isNull() ) {
Expand Down Expand Up @@ -714,7 +714,7 @@ cr3app::OnInit()
// load fonts from file
CRLog::debug("%d font files found", fonts.length());
if (!fontMan->GetFontCount()) {
for ( unsigned fi=0; fi<fonts.length(); fi++ ) {
for ( int fi=0; fi<fonts.length(); fi++ ) {
lString8 fn = UnicodeToLocal(fonts[fi]);
CRLog::trace("loading font: %s", fn.c_str());
if ( !fontMan->RegisterFont(fn) ) {
Expand Down
72 changes: 36 additions & 36 deletions crengine/include/lvstring.h
Expand Up @@ -29,31 +29,31 @@


/// strlen for lChar16
size_t lStr_len(const lChar16 * str);
int lStr_len(const lChar16 * str);
/// strlen for lChar8
size_t lStr_len(const lChar8 * str);
int lStr_len(const lChar8 * str);
/// strnlen for lChar16
size_t lStr_nlen(const lChar16 * str, size_t maxcount);
int lStr_nlen(const lChar16 * str, int maxcount);
/// strnlen for lChar8
size_t lStr_nlen(const lChar8 * str, size_t maxcount);
int lStr_nlen(const lChar8 * str, int maxcount);
/// strcpy for lChar16
size_t lStr_cpy(lChar16 * dst, const lChar16 * src);
int lStr_cpy(lChar16 * dst, const lChar16 * src);
/// strcpy for lChar16 -> lChar8
size_t lStr_cpy(lChar16 * dst, const lChar8 * src);
int lStr_cpy(lChar16 * dst, const lChar8 * src);
/// strcpy for lChar8
size_t lStr_cpy(lChar8 * dst, const lChar8 * src);
int lStr_cpy(lChar8 * dst, const lChar8 * src);
/// strncpy for lChar16
size_t lStr_ncpy(lChar16 * dst, const lChar16 * src, size_t maxcount);
int lStr_ncpy(lChar16 * dst, const lChar16 * src, int maxcount);
/// strncpy for lChar8
size_t lStr_ncpy(lChar8 * dst, const lChar8 * src, size_t maxcount);
int lStr_ncpy(lChar8 * dst, const lChar8 * src, int maxcount);
/// memcpy for lChar16
void lStr_memcpy(lChar16 * dst, const lChar16 * src, size_t count);
void lStr_memcpy(lChar16 * dst, const lChar16 * src, int count);
/// memcpy for lChar8
void lStr_memcpy(lChar8 * dst, const lChar8 * src, size_t count);
void lStr_memcpy(lChar8 * dst, const lChar8 * src, int count);
/// memset for lChar16
void lStr_memset(lChar16 * dst, lChar16 value, size_t count);
void lStr_memset(lChar16 * dst, lChar16 value, int count);
/// memset for lChar8
void lStr_memset(lChar8 * dst, lChar8 value, size_t count);
void lStr_memset(lChar8 * dst, lChar8 value, int count);
/// strcmp for lChar16
int lStr_cmp(const lChar16 * str1, const lChar16 * str2);
/// strcmp for lChar16 <> lChar8
Expand Down Expand Up @@ -159,7 +159,7 @@ class lString8
public:
// typedefs for STL compatibility
typedef lChar8 value_type; ///< character type
typedef size_t size_type; ///< size type
typedef int size_type; ///< size type
typedef int difference_type; ///< difference type
typedef value_type * pointer; ///< pointer to char type
typedef value_type & reference; ///< reference to char type
Expand Down Expand Up @@ -392,7 +392,7 @@ class lString16
public:
// typedefs for STL compatibility
typedef lChar16 value_type;
typedef size_t size_type;
typedef int size_type;
typedef int difference_type;
typedef value_type * pointer;
typedef value_type & reference;
Expand Down Expand Up @@ -652,8 +652,8 @@ class lString16Collection
{
private:
lstring_chunk_t * * chunks;
size_t count;
size_t size;
int count;
int size;
public:
lString16Collection()
: chunks(NULL), count(0), size(0)
Expand All @@ -662,29 +662,29 @@ class lString16Collection
void parse( lString16 string, lChar16 delimiter, bool flgTrim );
/// parse delimiter-separated string
void parse( lString16 string, lString16 delimiter, bool flgTrim );
void reserve( size_t space );
size_t add( const lString16 & str );
size_t add(const lChar16 * str) { add(lString16(str)); }
size_t add(const lChar8 * str) { add(lString16(str)); }
void reserve(int space);
int add( const lString16 & str );
int add(const lChar16 * str) { add(lString16(str)); }
int add(const lChar8 * str) { add(lString16(str)); }
void addAll( const lString16Collection & v )
{
for ( unsigned i=0; i<v.length(); i++ )
add( v[i] );
}
void erase(int offset, int count);
const lString16 & at( size_t index )
const lString16 & at(int index)
{
return ((lString16 *)chunks)[index];
}
const lString16 & operator [] ( size_t index ) const
const lString16 & operator [] (int index) const
{
return ((lString16 *)chunks)[index];
}
lString16 & operator [] ( size_t index )
lString16 & operator [] (int index)
{
return ((lString16 *)chunks)[index];
}
size_t length() const { return count; }
int length() const { return count; }
void clear();
bool contains( lString16 value )
{
Expand All @@ -706,8 +706,8 @@ class lString8Collection
{
private:
lstring_chunk_t * * chunks;
size_t count;
size_t size;
int count;
int size;
public:
lString8Collection()
: chunks(NULL), count(0), size(0)
Expand All @@ -717,24 +717,24 @@ class lString8Collection
{
split(str, delimiter);
}
void reserve( size_t space );
size_t add(const lString8 & str);
void reserve(int space);
int add(const lString8 & str);
/// split string by delimiters, and add all substrings to collection
void split(const lString8 & str, const lString8 & delimiter);
void erase(int offset, int count);
const lString8 & at( size_t index )
const lString8 & at(int index)
{
return ((lString8 *)chunks)[index];
}
const lString8 & operator [] ( size_t index ) const
const lString8 & operator [] (int index) const
{
return ((lString8 *)chunks)[index];
}
lString8 & operator [] ( size_t index )
lString8 & operator [] (int index)
{
return ((lString8 *)chunks)[index];
}
size_t length() const { return count; }
int length() const { return count; }
void clear();
~lString8Collection()
{
Expand All @@ -751,7 +751,7 @@ class SerialBuf;
class lString16HashedCollection : public lString16Collection
{
private:
size_t hashSize;
int hashSize;
struct HashPair {
int index;
HashPair * next;
Expand All @@ -771,8 +771,8 @@ class lString16HashedCollection : public lString16Collection
lString16HashedCollection( lString16HashedCollection & v );
lString16HashedCollection( lUInt32 hashSize );
~lString16HashedCollection();
size_t add( const lChar16 * s );
size_t find( const lChar16 * s );
int add( const lChar16 * s );
int find( const lChar16 * s );
};

/// returns true if two wide strings are equal
Expand Down
4 changes: 2 additions & 2 deletions crengine/src/chmfmt.cpp
Expand Up @@ -1069,7 +1069,7 @@ class CHMTOCReader {

if ( hhcName.empty() ) {
_fakeToc = true;
for ( unsigned i=0; i<urlList.length(); i++ ) {
for ( int i=0; i<urlList.length(); i++ ) {
//lString16 name = lString16::itoa(i+1);
lString16 name = urlList[i];
if ( name.endsWith(".htm") )
Expand Down Expand Up @@ -1106,7 +1106,7 @@ class CHMTOCReader {
// body element
recurseToc( body, 0 );
// add rest of pages
for ( unsigned i=0; i<urlList.length(); i++ ) {
for ( int i=0; i<urlList.length(); i++ ) {
lString16 name = urlList[i];
if ( name.endsWith(".htm") || name.endsWith(".html") )
addFile(name);
Expand Down

0 comments on commit 641e1c8

Please sign in to comment.