Skip to content

Commit

Permalink
fix language chaeck with unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed May 12, 2018
1 parent c520b65 commit 348d00e
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 116 deletions.
94 changes: 56 additions & 38 deletions gbt7714-plain.bst
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,7 @@ FUNCTION {emphasize}
if$
}

INTEGERS { ascii }

FUNCTION {get.char.lang}
{ chr.to.int$ 'ascii :=
ascii #64 > ascii #91 < and ascii #96 > ascii #123 < and or
{ lang.en }
{ ascii #227 > ascii #234 < and
{ lang.zh }
{ ascii #227 =
{ lang.ja }
{ ascii #207 > ascii #212 < and
{ lang.ru }
{ lang.en }
if$
}
if$
}
if$
}
if$
}
INTEGERS { byte second.byte }

INTEGERS { char.lang tmp.lang }

Expand All @@ -297,29 +277,67 @@ STRINGS { tmp.str }
FUNCTION {get.str.lang}
{ 'tmp.str :=
lang.other 'tmp.lang :=
tmp.str empty$
{ "Empty string!" warning$ }
{ #1 'charptr :=
tmp.str text.length$ #1 + 'len :=
{ charptr len < }
{ tmp.str charptr #1 substring$ get.char.lang 'char.lang :=
char.lang tmp.lang >
{ char.lang 'tmp.lang := }
'skip$
#1 'charptr :=
tmp.str text.length$ #1 + 'len :=
{ charptr len < }
{ tmp.str charptr #1 substring$ chr.to.int$ 'byte :=
byte #128 <
{ charptr #1 + 'charptr :=
byte #64 > byte #91 < and byte #96 > byte #123 < and or
{ lang.en 'char.lang := }
{ lang.other 'char.lang := }
if$

char.lang lang.zh = char.lang lang.ja = or
{ charptr #3 + 'charptr := }
{ char.lang lang.ru =
{ charptr #2 + 'charptr := }
{ charptr #1 + 'charptr := }
}
{ tmp.str charptr #1 + #1 substring$ chr.to.int$ 'second.byte :=
byte #224 <
{ charptr #2 + 'charptr :=
byte #207 > byte #212 < and
byte #212 = second.byte #176 < and or
{ lang.ru 'char.lang := }
{ lang.other 'char.lang := }
if$
}
{ byte #240 <
{ charptr #3 + 'charptr :=
byte #227 > byte #234 < and
{ lang.zh 'char.lang := }
{ byte #227 =
{ second.byte #143 >
{ lang.zh 'char.lang := }
{ second.byte #128 > second.byte #132 < and
{ lang.ja 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
{ byte #239 =
second.byte #163 > second.byte #172 < and and
{ lang.zh 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
if$
}
{ charptr #4 + 'charptr :=
byte #240 = second.byte #159 > and
{ lang.zh 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
if$
}
while$
if$
char.lang tmp.lang >
{ char.lang 'tmp.lang := }
'skip$
if$
}
if$
while$
tmp.lang
}

Expand Down
94 changes: 56 additions & 38 deletions gbt7714-unsrt.bst
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,7 @@ FUNCTION {emphasize}
if$
}

INTEGERS { ascii }

FUNCTION {get.char.lang}
{ chr.to.int$ 'ascii :=
ascii #64 > ascii #91 < and ascii #96 > ascii #123 < and or
{ lang.en }
{ ascii #227 > ascii #234 < and
{ lang.zh }
{ ascii #227 =
{ lang.ja }
{ ascii #207 > ascii #212 < and
{ lang.ru }
{ lang.en }
if$
}
if$
}
if$
}
if$
}
INTEGERS { byte second.byte }

INTEGERS { char.lang tmp.lang }

Expand All @@ -297,29 +277,67 @@ STRINGS { tmp.str }
FUNCTION {get.str.lang}
{ 'tmp.str :=
lang.other 'tmp.lang :=
tmp.str empty$
{ "Empty string!" warning$ }
{ #1 'charptr :=
tmp.str text.length$ #1 + 'len :=
{ charptr len < }
{ tmp.str charptr #1 substring$ get.char.lang 'char.lang :=
char.lang tmp.lang >
{ char.lang 'tmp.lang := }
'skip$
#1 'charptr :=
tmp.str text.length$ #1 + 'len :=
{ charptr len < }
{ tmp.str charptr #1 substring$ chr.to.int$ 'byte :=
byte #128 <
{ charptr #1 + 'charptr :=
byte #64 > byte #91 < and byte #96 > byte #123 < and or
{ lang.en 'char.lang := }
{ lang.other 'char.lang := }
if$

char.lang lang.zh = char.lang lang.ja = or
{ charptr #3 + 'charptr := }
{ char.lang lang.ru =
{ charptr #2 + 'charptr := }
{ charptr #1 + 'charptr := }
}
{ tmp.str charptr #1 + #1 substring$ chr.to.int$ 'second.byte :=
byte #224 <
{ charptr #2 + 'charptr :=
byte #207 > byte #212 < and
byte #212 = second.byte #176 < and or
{ lang.ru 'char.lang := }
{ lang.other 'char.lang := }
if$
}
{ byte #240 <
{ charptr #3 + 'charptr :=
byte #227 > byte #234 < and
{ lang.zh 'char.lang := }
{ byte #227 =
{ second.byte #143 >
{ lang.zh 'char.lang := }
{ second.byte #128 > second.byte #132 < and
{ lang.ja 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
{ byte #239 =
second.byte #163 > second.byte #172 < and and
{ lang.zh 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
if$
}
{ charptr #4 + 'charptr :=
byte #240 = second.byte #159 > and
{ lang.zh 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
if$
}
while$
if$
char.lang tmp.lang >
{ char.lang 'tmp.lang := }
'skip$
if$
}
if$
while$
tmp.lang
}

Expand Down
118 changes: 79 additions & 39 deletions gbt7714.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ version 2005/12/01 or later.
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{gbt7714}
%<*package>
[2018/05/10 v1.0.6 GB/T 7714-2015 BibTeX Style]
[2018/05/12 v1.0.7 GB/T 7714-2015 BibTeX Style]
%</package>
%
%<*driver>
Expand Down Expand Up @@ -153,6 +153,7 @@ version 2005/12/01 or later.
% \changes{v1.0.5}{2018/04/18}{允许著录多个 DOI}
% \changes{v1.0.6}{2018/05/10}{不再处理中文标题的英文单词的大小写}
% \changes{v1.0.6}{2018/05/10}{文献列表的数字标签左对齐}
% \changes{v1.0.7}{2018/05/12}{修正了检测 Unicode 语言}
%
%
% \section{简介}
Expand Down Expand Up @@ -1032,27 +1033,7 @@ FUNCTION {emphasize}
if$
}
INTEGERS { ascii }
FUNCTION {get.char.lang}
{ chr.to.int$ 'ascii :=
ascii #64 > ascii #91 < and ascii #96 > ascii #123 < and or
{ lang.en }
{ ascii #227 > ascii #234 < and
{ lang.zh }
{ ascii #227 =
{ lang.ja }
{ ascii #207 > ascii #212 < and
{ lang.ru }
{ lang.en }
if$
}
if$
}
if$
}
if$
}
INTEGERS { byte second.byte }
INTEGERS { char.lang tmp.lang }
Expand All @@ -1061,29 +1042,88 @@ STRINGS { tmp.str }
FUNCTION {get.str.lang}
{ 'tmp.str :=
lang.other 'tmp.lang :=
tmp.str empty$
{ "Empty string!" warning$ }
{ #1 'charptr :=
tmp.str text.length$ #1 + 'len :=
{ charptr len < }
{ tmp.str charptr #1 substring$ get.char.lang 'char.lang :=
char.lang tmp.lang >
{ char.lang 'tmp.lang := }
'skip$
#1 'charptr :=
tmp.str text.length$ #1 + 'len :=
{ charptr len < }
{ tmp.str charptr #1 substring$ chr.to.int$ 'byte :=
byte #128 <
{ charptr #1 + 'charptr :=
byte #64 > byte #91 < and byte #96 > byte #123 < and or
{ lang.en 'char.lang := }
{ lang.other 'char.lang := }
if$
char.lang lang.zh = char.lang lang.ja = or
{ charptr #3 + 'charptr := }
{ char.lang lang.ru =
{ charptr #2 + 'charptr := }
{ charptr #1 + 'charptr := }
}
{ tmp.str charptr #1 + #1 substring$ chr.to.int$ 'second.byte :=
byte #224 <
% \end{macrocode}
% 俄文西里尔字母:U+0400 到 U+052F,对应 UTF-8 从 D0 80 到 D4 AF。
% \begin{macrocode}
{ charptr #2 + 'charptr :=
byte #207 > byte #212 < and
byte #212 = second.byte #176 < and or
{ lang.ru 'char.lang := }
{ lang.other 'char.lang := }
if$
}
{ byte #240 <
% \end{macrocode}
% CJK Unified Ideographs: U+4E00--U+9FFF; UTF-8: E4 B8 80--E9 BF BF.
% \begin{macrocode}
{ charptr #3 + 'charptr :=
byte #227 > byte #234 < and
{ lang.zh 'char.lang := }
% \end{macrocode}
% CJK Unified Ideographs Extension A: U+3400--U+4DBF; UTF-8: E3 90 80--E4 B6 BF.
% \begin{macrocode}
{ byte #227 =
{ second.byte #143 >
{ lang.zh 'char.lang := }
% \end{macrocode}
% 日语假名:U+3040--U+30FF, UTF-8: E3 81 80--E3 83 BF.
% \begin{macrocode}
{ second.byte #128 > second.byte #132 < and
{ lang.ja 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
% \end{macrocode}
% CJK Compatibility Ideographs: U+F900--U+FAFF, UTF-8: EF A4 80--EF AB BF.
% \begin{macrocode}
{ byte #239 =
second.byte #163 > second.byte #172 < and and
{ lang.zh 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
if$
}
% \end{macrocode}
% CJK Unified Ideographs Extension B--F: U+20000--U+2EBEF,
% UTF-8: F0 A0 80 80--F0 AE AF AF.
% CJK Compatibility Ideographs Supplement: U+2F800--U+2FA1F,
% UTF-8: F0 AF A0 80--F0 AF A8 9F.
% \begin{macrocode}
{ charptr #4 + 'charptr :=
byte #240 = second.byte #159 > and
{ lang.zh 'char.lang := }
{ lang.other 'char.lang := }
if$
}
if$
}
if$
}
while$
if$
char.lang tmp.lang >
{ char.lang 'tmp.lang := }
'skip$
if$
}
if$
while$
tmp.lang
}
Expand Down
2 changes: 1 addition & 1 deletion gbt7714.sty
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{gbt7714}
[2018/05/10 v1.0.6 GB/T 7714-2015 BibTeX Style]
[2018/05/12 v1.0.7 GB/T 7714-2015 BibTeX Style]
\newif\if@gbt@numerical
\newif\if@gbt@super
\DeclareOption{super}{\@gbt@numericaltrue\@gbt@supertrue}
Expand Down

0 comments on commit 348d00e

Please sign in to comment.