Skip to content

Commit

Permalink
opt: refactor folding auto-generate file
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Jul 5, 2023
1 parent 07615d9 commit cae2582
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/common/folding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */

#include "folding.hh"
#include <QRegularExpression>

#include "utf8.hh"
#include "globalregex.hh"
#include "inc_case_folding.hh"

namespace Folding {

#include "inc_case_folding.hh"

/// Tests if the given char is one of the Unicode combining marks. Some are
/// caught by the diacritics folding table, but they are only handled there
Expand Down
6 changes: 3 additions & 3 deletions src/common/inc_case_folding.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// This file was generated automatically. Do not edit directly.

#pragma once
enum { foldCaseMaxOut = 3 };

size_t foldCase( wchar in, wchar * out )
inline size_t foldCase( char32_t in, char32_t * out )
{
switch( in )
{
Expand Down Expand Up @@ -1540,7 +1540,7 @@ size_t foldCase( wchar in, wchar * out )
}
}

wchar foldCaseSimple( wchar in )
char32_t foldCaseSimple( char32_t in )
{
switch( in )
{
Expand Down
5 changes: 3 additions & 2 deletions tools/generators/generate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ int main()

fprintf( outf, "// This file was generated automatically. Do not edit directly.\n\n" );

fprintf( outf, "#pragma once\n\n" );
fprintf( outf, "enum { foldCaseMaxOut = 3 };\n\n" );
fprintf( outf, "size_t foldCase( wchar in, wchar * out )\n{\n switch( in )\n {\n" );
fprintf( outf, "inline size_t foldCase( char32_t in, char32_t * out )\n{\n switch( in )\n {\n" );

for ( map< char32_t, u32string >::const_iterator i = foldTable.begin(); i != foldTable.end(); ++i ) {
if ( i->second.size() == 1 )
Expand All @@ -183,7 +184,7 @@ int main()
fprintf( outf, " default: *out = in; return 1;\n" );
fprintf( outf, " }\n}\n\n" );

fprintf( outf, "wchar foldCaseSimple( wchar in )\n{\n switch( in )\n {\n" );
fprintf( outf, "char32_t foldCaseSimple( char32_t in )\n{\n switch( in )\n {\n" );

for ( map< char32_t, char32_t >::const_iterator i = simpleFoldTable.begin(); i != simpleFoldTable.end(); ++i )
fprintf( outf, " case 0x%x: return 0x%x;\n", i->first, i->second );
Expand Down

0 comments on commit cae2582

Please sign in to comment.