浏览代码

ft: 代码调整

master
SisMaker 4 年前
父节点
当前提交
ffed4777ff
共有 1 个文件被更改,包括 52 次插入26 次删除
  1. +52
    -26
      src/eAcs.erl

+ 52
- 26
src/eAcs.erl 查看文件

@ -140,12 +140,12 @@ replaceSw(BinStr) ->
doReplaceSw([], BinStr, TotalSize, StartPos, BinAcc) -> doReplaceSw([], BinStr, TotalSize, StartPos, BinAcc) ->
case TotalSize > StartPos of case TotalSize > StartPos of
true -> true ->
<<BinAcc/binary, (binary:part(BinStr, StartPos, TotalSize - StartPos))/binary>>;
<<BinAcc/binary, (binary:part(BinStr, StartPos, TotalSize - StartPos))/binary>>;
_ -> _ ->
BinAcc BinAcc
end; end;
doReplaceSw([{CurByteIndex, MatchWordCnt, _CurWordIndex} | MatchBIMWs], BinStr, TotalSize, StartPos, BinAcc) -> doReplaceSw([{CurByteIndex, MatchWordCnt, _CurWordIndex} | MatchBIMWs], BinStr, TotalSize, StartPos, BinAcc) ->
{EndByteIndex, FilterWs} = getMatchWords(MatchWordCnt, BinStr, CurByteIndex, _BslCnt = 0, _Utf8Code = 0, []),
{EndByteIndex, FilterWs} = getMatchWords(MatchWordCnt, BinStr, CurByteIndex, []),
RPStr = unicode:characters_to_binary(FilterWs, utf8), RPStr = unicode:characters_to_binary(FilterWs, utf8),
case StartPos =< EndByteIndex of case StartPos =< EndByteIndex of
true -> true ->
@ -155,40 +155,66 @@ doReplaceSw([{CurByteIndex, MatchWordCnt, _CurWordIndex} | MatchBIMWs], BinStr,
end, end,
doReplaceSw(MatchBIMWs, BinStr, TotalSize, CurByteIndex + 1, NewBinAcc). doReplaceSw(MatchBIMWs, BinStr, TotalSize, CurByteIndex + 1, NewBinAcc).
getMatchWords(0, _BinStr, ByteIndex, _BslCnt, _Utf8Code, FilterWs) ->
getMatchWords(0, _BinStr, ByteIndex, FilterWs) ->
{ByteIndex, FilterWs}; {ByteIndex, FilterWs};
getMatchWords(MatchWordCnt, BinStr, ByteIndex, BslCnt, Utf8Code, FilterWs) ->
getMatchWords(MatchWordCnt, BinStr, ByteIndex, FilterWs) ->
Byte = binary:at(BinStr, ByteIndex), Byte = binary:at(BinStr, ByteIndex),
if
Byte < 128 ->
case Byte < 128 of
true ->
case acsSpw:getSpw(Byte) of case acsSpw:getSpw(Byte) of
true -> true ->
getMatchWords(MatchWordCnt, BinStr, ByteIndex - 1, 0, 0, [Byte | FilterWs]);
getMatchWords(MatchWordCnt, BinStr, ByteIndex - 1, [Byte | FilterWs]);
_ -> _ ->
getMatchWords(MatchWordCnt - 1, BinStr, ByteIndex - 1, 0, 0, [?RW | FilterWs])
getMatchWords(MatchWordCnt - 1, BinStr, ByteIndex - 1, [?RW | FilterWs])
end; end;
Byte bsr 6 == 2 ->
Code = Byte band 63,
getMatchWords(MatchWordCnt, BinStr, ByteIndex - 1, BslCnt + 6, Code bsl BslCnt + Utf8Code, FilterWs);
true ->
case BslCnt of
6 ->
Code = Byte band 31;
12 ->
Code = Byte band 15;
18 ->
Code = Byte band 7;
24 ->
Code = Byte band 3;
30 ->
Code = Byte band 1
_ ->
LUtf8Code = Byte band 63,
LLByte = binary:at(BinStr, ByteIndex - 1),
case LLByte bsr 6 == 2 of
true ->
LLUtf8Code = LLByte band 63,
LLLByte = binary:at(BinStr, ByteIndex - 2),
case LLLByte bsr 6 == 2 of
true ->
LLLUtf8Code = LLLByte band 63,
LLLLByte = binary:at(BinStr, ByteIndex - 3),
case LLLLByte bsr 6 == 2 of
true ->
LLLLUtf8Code = LLLLByte band 63,
LLLLLByte = binary:at(BinStr, ByteIndex - 4),
case LLLLLByte bsr 6 == 2 of
true ->
LLLLLUtf8Code = LLLLLByte band 63,
LLLLLLByte = binary:at(BinStr, ByteIndex - 5),
LLLLLLUtf8Code = LLLLLLByte band 1,
ReduceCnt = 6,
FullWord = LLLLLLUtf8Code bsl 30 bor LLLLLUtf8Code bsl 24 bor LLLLUtf8Code bsl 18 bor LLLUtf8Code bsl 12 bor LLUtf8Code bsl 6 bor LUtf8Code;
_ ->
LLLLLUtf8Code = LLLLLByte band 3,
ReduceCnt = 5,
FullWord = LLLLLUtf8Code bsl 24 bor LLLLUtf8Code bsl 18 bor LLLUtf8Code bsl 12 bor LLUtf8Code bsl 6 bor LUtf8Code
end;
_ ->
LLLLUtf8Code = LLLLByte band 7,
ReduceCnt = 4,
FullWord = LLLLUtf8Code bsl 18 bor LLLUtf8Code bsl 12 bor LLUtf8Code bsl 6 bor LUtf8Code
end;
_ ->
LLLUtf8Code = LLLByte band 15,
ReduceCnt = 3,
FullWord = LLLUtf8Code bsl 12 bor LLUtf8Code bsl 6 bor LUtf8Code
end;
_ ->
LLUtf8Code = LLByte band 31,
ReduceCnt = 2,
FullWord = LLUtf8Code bsl 6 bor LUtf8Code
end, end,
FullWord = Code bsl BslCnt + Utf8Code,
case acsSpw:getSpw(FullWord) of case acsSpw:getSpw(FullWord) of
true -> true ->
getMatchWords(MatchWordCnt, BinStr, ByteIndex - 1, 0, 0, [FullWord | FilterWs]);
getMatchWords(MatchWordCnt, BinStr, ByteIndex - ReduceCnt, [FullWord | FilterWs]);
_ -> _ ->
getMatchWords(MatchWordCnt - 1, BinStr, ByteIndex - 1, 0, 0, [?RW | FilterWs])
getMatchWords(MatchWordCnt - 1, BinStr, ByteIndex - ReduceCnt, [?RW | FilterWs])
end end
end. end.

正在加载...
取消
保存