Skip to content

Commit

Permalink
Merge branch 'staged' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Feb 18, 2022
2 parents 092e81a + cc9b648 commit 53e6fca
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 166 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release_drafter_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:
branches:
- staged
# pull_request event is required only for autolabeler
# pull_request:
# # Only following types are handled by the action, but one can default to all as well
# types: [opened, reopened, synchronize]
# # pull_request_target event is required for autolabeler to support PRs from forks
# # pull_request_target:
# # types: [opened, reopened, synchronize]
pull_request:
# Only following types are handled by the action, but one can default to all as well
# types: [opened, reopened, synchronize]
# pull_request_target event is required for autolabeler to support PRs from forks
# pull_request_target:
# types: [opened, reopened, synchronize]

jobs:
update_release_draft:
Expand Down
4 changes: 2 additions & 2 deletions dictdfiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ QString const& DictdDictionary::getDescription()
if( !dictionaryDescription.isEmpty() )
return dictionaryDescription;

sptr< Dictionary::DataRequest > req = getArticle( GD_NATIVE_TO_WS( L"00databaseinfo" ),
vector< wstring >(), wstring(), false );
sptr< Dictionary::DataRequest > req =
getArticle( U"00databaseinfo" , vector< wstring >(), wstring(), false );

if( req->dataSize() > 0 )
dictionaryDescription = Html::unescape( QString::fromUtf8( req->getFullData().data(), req->getFullData().size() ), true );
Expand Down
118 changes: 49 additions & 69 deletions dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void DslDictionary::loadArticle( uint32_t address,
if ( !articleBody )
{
// throw exCantReadFile( getDictionaryFilenames()[ 0 ] );
articleData = GD_NATIVE_TO_WS( L"\n\r\t" ) + gd::toWString( QString( "DICTZIP error: " ) + dict_error_str( dz ) );
articleData = U"\n\r\t" + gd::toWString( QString( "DICTZIP error: " ) + dict_error_str( dz ) );
}
else
{
Expand Down Expand Up @@ -616,7 +616,7 @@ void DslDictionary::loadArticle( uint32_t address,
{
size_t begin = pos;

pos = articleData.find_first_of( GD_NATIVE_TO_WS( L"\n\r" ), begin );
pos = articleData.find_first_of( U"\n\r" , begin );

if ( pos == wstring::npos )
pos = articleData.size();
Expand Down Expand Up @@ -741,7 +741,7 @@ void DslDictionary::loadArticle( uint32_t address,
if( insidedCard )
{
// Check for next insided headword
wstring::size_type hpos = articleData.find_first_of( GD_NATIVE_TO_WS( L"\n\r" ), pos );
wstring::size_type hpos = articleData.find_first_of( U"\n\r" , pos );
if ( hpos == wstring::npos )
hpos = articleData.size();

Expand Down Expand Up @@ -820,13 +820,11 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
return result;
}

if ( node.tagName == GD_NATIVE_TO_WS( L"b" ) )
if( node.tagName == U"b" )
result += "<b class=\"dsl_b\">" + processNodeChildren( node ) + "</b>";
else
if ( node.tagName == GD_NATIVE_TO_WS( L"i" ) )
else if( node.tagName == U"i" )
result += "<i class=\"dsl_i\">" + processNodeChildren( node ) + "</i>";
else
if ( node.tagName == GD_NATIVE_TO_WS( L"u" ) )
else if( node.tagName == U"u" )
{
string nodeText = processNodeChildren( node );

Expand All @@ -836,39 +834,32 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )

result += "<span class=\"dsl_u\">" + nodeText + "</span>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"c" ) )
else if( node.tagName == U"c" )
{
result += "<font color=\"" + ( node.tagAttrs.size() ?
Html::escape( Utf8::encode( node.tagAttrs ) ) : string( "c_default_color" ) )
+ "\">" + processNodeChildren( node ) + "</font>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"*" ) )
else if( node.tagName == U"*" )
{
string id = "O" + getId().substr( 0, 7 ) + "_" +
QString::number( articleNom ).toStdString() +
"_opt_" + QString::number( optionalPartNom++ ).toStdString();
result += "<span class=\"dsl_opt\" id=\"" + id + "\">" + processNodeChildren( node ) + "</span>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"m" ) )
result += "<div class=\"dsl_m\">" + processNodeChildren( node ) + "</div>";
else if( node.tagName == U"m" )
result += "<div class=\"dsl_m\">" + processNodeChildren( node ) + "</div>";
else
if ( node.tagName.size() == 2 && node.tagName[ 0 ] == L'm' &&
iswdigit( node.tagName[ 1 ] ) )
result += "<div class=\"dsl_" + Utf8::encode( node.tagName ) + "\">" + processNodeChildren( node ) + "</div>";
else
if ( node.tagName == GD_NATIVE_TO_WS( L"trn" ) )
else if( node.tagName == U"trn" )
result += "<span class=\"dsl_trn\">" + processNodeChildren( node ) + "</span>";
else
if ( node.tagName == GD_NATIVE_TO_WS( L"ex" ) )
else if( node.tagName == U"ex" )
result += "<span class=\"dsl_ex\">" + processNodeChildren( node ) + "</span>";
else
if ( node.tagName == GD_NATIVE_TO_WS( L"com" ) )
else if( node.tagName == U"com" )
result += "<span class=\"dsl_com\">" + processNodeChildren( node ) + "</span>";
else
if ( node.tagName == GD_NATIVE_TO_WS( L"s" ) || node.tagName == GD_NATIVE_TO_WS( L"video" ) )
else if( node.tagName == U"s" || node.tagName == U"video" )
{
string filename = Filetype::simplifyString( Utf8::encode( node.renderAsText() ), false );
string n = resourceDir1 + FsEncoding::encode( filename );
Expand Down Expand Up @@ -1013,8 +1004,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
+ "\">" + processNodeChildren( node ) + "</a>";
}
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"url" ) )
else if( node.tagName == U"url" )
{
string link = Html::escape( Filetype::simplifyString( Utf8::encode( node.renderAsText() ), false ) );
if( QUrl::fromEncoded( link.c_str() ).scheme().isEmpty() )
Expand All @@ -1037,13 +1027,11 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )

result += "<a class=\"dsl_url\" href=\"" + link +"\">" + processNodeChildren( node ) + "</a>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"!trs" ) )
else if( node.tagName == U"!trs" )
{
result += "<span class=\"dsl_trs\">" + processNodeChildren( node ) + "</span>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"p") )
else if( node.tagName == U"p" )
{
result += "<span class=\"dsl_p\"";

Expand Down Expand Up @@ -1090,8 +1078,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )

result += ">" + processNodeChildren( node ) + "</span>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"'" ) )
else if( node.tagName == U"'" )
{
// There are two ways to display the stress: by adding an accent sign or via font styles.
// We generate two spans, one with accented data and another one without it, so the
Expand All @@ -1101,8 +1088,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
+ "<span class=\"dsl_stress_with_accent\">" + data + Utf8::encode( wstring( 1, 0x301 ) )
+ "</span></span>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"lang" ) )
else if( node.tagName == U"lang" )
{
result += "<span class=\"dsl_lang\"";
if( !node.tagAttrs.empty() )
Expand Down Expand Up @@ -1135,8 +1121,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
}
result += ">" + processNodeChildren( node ) + "</span>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"ref" ) )
else if( node.tagName == U"ref" )
{
QUrl url;

Expand All @@ -1158,8 +1143,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
result += string( "<a class=\"dsl_ref\" href=\"" ) + url.toEncoded().data() +"\">"
+ processNodeChildren( node ) + "</a>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"@" ) )
else if( node.tagName == U"@" )
{
// Special case - insided card header was not parsed

Expand All @@ -1174,23 +1158,19 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
result += string( "<a class=\"dsl_ref\" href=\"" ) + url.toEncoded().data() +"\">"
+ processNodeChildren( node ) + "</a>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"sub" ) )
else if( node.tagName == U"sub" )
{
result += "<sub>" + processNodeChildren( node ) + "</sub>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"sup" ) )
else if( node.tagName == U"sup" )
{
result += "<sup>" + processNodeChildren( node ) + "</sup>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"t" ) )
else if( node.tagName == U"t" )
{
result += "<span class=\"dsl_t\">" + processNodeChildren( node ) + "</span>";
}
else
if ( node.tagName == GD_NATIVE_TO_WS( L"br" ) )
else if( node.tagName == U"br" )
{
result += "<br />";
}
Expand Down Expand Up @@ -1377,7 +1357,7 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,
{
size_t begin = pos;

pos = articleData.find_first_of( GD_NATIVE_TO_WS( L"\n\r" ), begin );
pos = articleData.find_first_of( U"\n\r" , begin );

if ( articleHeadword.empty() )
{
Expand Down Expand Up @@ -1445,7 +1425,7 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,
if( insidedCard )
{
// Check for next insided headword
wstring::size_type hpos = articleData.find_first_of( GD_NATIVE_TO_WS( L"\n\r" ), pos );
wstring::size_type hpos = articleData.find_first_of( U"\n\r" , pos );
if ( hpos == wstring::npos )
hpos = articleData.size();

Expand Down Expand Up @@ -2075,37 +2055,37 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
try { // Here we intercept any errors during the read to save line at
// which the incident happened. We need alive scanner for that.

if ( scanner.getDictionaryName() == GD_NATIVE_TO_WS( L"Abbrev" ) )
continue; // For now just skip abbreviations
if( scanner.getDictionaryName() == U"Abbrev" )
continue; // For now just skip abbreviations

// Building the index
initializing.indexingDictionary( Utf8::encode( scanner.getDictionaryName() ) );
// Building the index
initializing.indexingDictionary( Utf8::encode( scanner.getDictionaryName() ) );

gdDebug( "Dsl: Building the index for dictionary: %s\n",
gd::toQString( scanner.getDictionaryName() ).toUtf8().data() );
gdDebug( "Dsl: Building the index for dictionary: %s\n",
gd::toQString( scanner.getDictionaryName() ).toUtf8().data() );

File::Class idx( indexFile, "wb" );
File::Class idx( indexFile, "wb" );

IdxHeader idxHeader;
IdxHeader idxHeader;

memset( &idxHeader, 0, sizeof( idxHeader ) );
memset( &idxHeader, 0, sizeof( idxHeader ) );

// We write a dummy header first. At the end of the process the header
// will be rewritten with the right values.
// We write a dummy header first. At the end of the process the header
// will be rewritten with the right values.

idx.write( idxHeader );
idx.write( idxHeader );

string dictionaryName = Utf8::encode( scanner.getDictionaryName() );
string dictionaryName = Utf8::encode( scanner.getDictionaryName() );

idx.write( (uint32_t) dictionaryName.size() );
idx.write( dictionaryName.data(), dictionaryName.size() );
idx.write( (uint32_t)dictionaryName.size() );
idx.write( dictionaryName.data(), dictionaryName.size() );

string soundDictName = Utf8::encode( scanner.getSoundDictionaryName() );
if( !soundDictName.empty() )
{
idxHeader.hasSoundDictionaryName = 1;
idx.write( (uint32_t) soundDictName.size() );
idx.write( soundDictName.data(), soundDictName.size() );
string soundDictName = Utf8::encode( scanner.getSoundDictionaryName() );
if( !soundDictName.empty() )
{
idxHeader.hasSoundDictionaryName = 1;
idx.write( (uint32_t)soundDictName.size() );
idx.write( soundDictName.data(), soundDictName.size() );
}

idxHeader.dslEncoding = scanner.getEncoding();
Expand Down Expand Up @@ -2163,7 +2143,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
if ( eof )
break;

curString.erase( 0, curString.find_first_not_of( GD_NATIVE_TO_WS( L" \t" ) ) );
curString.erase( 0, curString.find_first_not_of( U" \t" ) );

if ( keys.size() )
expandTildes( curString, keys.front() );
Expand Down
Loading

0 comments on commit 53e6fca

Please sign in to comment.