|
|
@ -140,12 +140,12 @@ replaceSw(BinStr) -> |
|
|
|
doReplaceSw([], BinStr, TotalSize, StartPos, BinAcc) -> |
|
|
|
case TotalSize > StartPos of |
|
|
|
true -> |
|
|
|
<<BinAcc/binary, (binary:part(BinStr, StartPos, TotalSize - StartPos))/binary>>; |
|
|
|
<<BinAcc/binary, (binary:part(BinStr, StartPos, TotalSize - StartPos))/binary>>; |
|
|
|
_ -> |
|
|
|
BinAcc |
|
|
|
end; |
|
|
|
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), |
|
|
|
case StartPos =< EndByteIndex of |
|
|
|
true -> |
|
|
@ -155,40 +155,66 @@ doReplaceSw([{CurByteIndex, MatchWordCnt, _CurWordIndex} | MatchBIMWs], BinStr, |
|
|
|
end, |
|
|
|
doReplaceSw(MatchBIMWs, BinStr, TotalSize, CurByteIndex + 1, NewBinAcc). |
|
|
|
|
|
|
|
getMatchWords(0, _BinStr, ByteIndex, _BslCnt, _Utf8Code, FilterWs) -> |
|
|
|
getMatchWords(0, _BinStr, ByteIndex, FilterWs) -> |
|
|
|
{ByteIndex, FilterWs}; |
|
|
|
getMatchWords(MatchWordCnt, BinStr, ByteIndex, BslCnt, Utf8Code, FilterWs) -> |
|
|
|
getMatchWords(MatchWordCnt, BinStr, ByteIndex, FilterWs) -> |
|
|
|
Byte = binary:at(BinStr, ByteIndex), |
|
|
|
if |
|
|
|
Byte < 128 -> |
|
|
|
case Byte < 128 of |
|
|
|
true -> |
|
|
|
case acsSpw:getSpw(Byte) of |
|
|
|
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; |
|
|
|
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, |
|
|
|
FullWord = Code bsl BslCnt + Utf8Code, |
|
|
|
case acsSpw:getSpw(FullWord) of |
|
|
|
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. |
|
|
|
|
|
|
|