[frameworks/kcodecs] /: [KEncodingProber] Replace pointer to SMModel with reference
Stefan Brüns <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 48177139cd968e991e1d8ec436cd82075c99409f by Stefan Brüns.
Committed on 07/08/2026 at 13:10.
Pushed by bruns into branch 'master'.
[KEncodingProber] Replace pointer to SMModel with reference
The SMModel can and must never be null.
Also make the single argument constructor explicit.
M +5 -5 autotests/kencodingproberunittest.cpp
M +1 -1 src/probers/nsBig5Prober.cpp
M +6 -6 src/probers/nsCodingStateMachine.h
M +1 -1 src/probers/nsEUCJPProber.cpp
M +1 -1 src/probers/nsEUCKRProber.cpp
M +2 -2 src/probers/nsEscCharsetProber.cpp
M +1 -1 src/probers/nsGB2312Prober.cpp
M +1 -1 src/probers/nsSJISProber.cpp
https://invent.kde.org/frameworks/kcodecs/-/commit/48177139cd968e991e1d8ec436cd82075c99409f
diff --git a/autotests/kencodingproberunittest.cpp b/autotests/kencodingproberunittest.cpp
index 22e0211..9c3b958 100644
--- a/autotests/kencodingproberunittest.cpp
+++ b/autotests/kencodingproberunittest.cpp
@@ -43,7 +43,7 @@ void KEncodingProberUnitTest::testUtf8()
using namespace kencodingprober;
- nsCodingStateMachine stateMachine{&UTF8SMModel};
+ nsCodingStateMachine stateMachine{UTF8SMModel};
nsSMState state = eStart;
for (auto b : data) {
@@ -133,7 +133,7 @@ void KEncodingProberUnitTest::testUtf16BE()
using namespace kencodingprober;
- nsCodingStateMachine stateMachine{&UCS2BESMModel};
+ nsCodingStateMachine stateMachine{UCS2BESMModel};
nsSMState state = eStart;
QEXPECT_FAIL("UTF16 ZWNBSP little", "zero width no-break space rejected", Abort);
@@ -151,7 +151,7 @@ void KEncodingProberUnitTest::testUtf16LE()
using namespace kencodingprober;
- nsCodingStateMachine stateMachine{&UCS2LESMModel};
+ nsCodingStateMachine stateMachine{UCS2LESMModel};
nsSMState state = eStart;
QEXPECT_FAIL("UTF16 ZWNBSP big", "zero width no-break space rejected", Abort);
@@ -345,7 +345,7 @@ void KEncodingProberUnitTest::testHzCharset()
using namespace kencodingprober;
- nsCodingStateMachine stateMachine{&HZSMModel};
+ nsCodingStateMachine stateMachine{HZSMModel};
nsSMState state = eStart;
@@ -364,7 +364,7 @@ void KEncodingProberUnitTest::testIso2022JPCharset()
using namespace kencodingprober;
- nsCodingStateMachine stateMachine{&ISO2022JPSMModel};
+ nsCodingStateMachine stateMachine{ISO2022JPSMModel};
nsSMState state = eStart;
diff --git a/src/probers/nsBig5Prober.cpp b/src/probers/nsBig5Prober.cpp
index d58dc2d..f2b782c 100644
--- a/src/probers/nsBig5Prober.cpp
+++ b/src/probers/nsBig5Prober.cpp
@@ -10,7 +10,7 @@
namespace kencodingprober
{
nsBig5Prober::nsBig5Prober()
- : mCodingSM{std::make_unique<nsCodingStateMachine>(&Big5SMModel)}
+ : mCodingSM{std::make_unique<nsCodingStateMachine>(Big5SMModel)}
{
}
diff --git a/src/probers/nsCodingStateMachine.h b/src/probers/nsCodingStateMachine.h
index 2b85d57..4aeccc9 100644
--- a/src/probers/nsCodingStateMachine.h
+++ b/src/probers/nsCodingStateMachine.h
@@ -37,7 +37,7 @@ typedef struct {
class KCODECS_NO_EXPORT nsCodingStateMachine
{
public:
- nsCodingStateMachine(const SMModel *sm)
+ explicit nsCodingStateMachine(const SMModel &sm)
: mModel(sm)
{
}
@@ -45,12 +45,12 @@ public:
{
// for each byte we get its class, if it is first byte, we also get byte length
const uint8_t index = static_cast<uint8_t>(c);
- unsigned int byteCls = mModel->classTable[index];
+ unsigned int byteCls = mModel.classTable[index];
if (mCurrentState == eStart) {
- mCurrentCharLen = mModel->charLenTable[byteCls];
+ mCurrentCharLen = mModel.charLenTable[byteCls];
}
// from byte's class and stateTable, we get its next state
- mCurrentState = mModel->stateTable[mCurrentState * mModel->classFactor + byteCls];
+ mCurrentState = mModel.stateTable[mCurrentState * mModel.classFactor + byteCls];
return mCurrentState;
}
unsigned int GetCurrentCharLen(void)
@@ -59,7 +59,7 @@ public:
}
const char *GetCodingStateMachine()
{
- return mModel->name;
+ return mModel.name;
}
const char *DumpCurrentState()
{
@@ -79,7 +79,7 @@ protected:
int mCurrentState = eStart;
unsigned int mCurrentCharLen = 0;
- const SMModel *mModel = nullptr;
+ const SMModel &mModel;
};
}
#endif /* nsCodingStateMachine_h__ */
diff --git a/src/probers/nsEUCJPProber.cpp b/src/probers/nsEUCJPProber.cpp
index 973490c..1e88f9b 100644
--- a/src/probers/nsEUCJPProber.cpp
+++ b/src/probers/nsEUCJPProber.cpp
@@ -15,7 +15,7 @@
namespace kencodingprober
{
nsEUCJPProber::nsEUCJPProber()
- : mCodingSM{std::make_unique<nsCodingStateMachine>(&EUCJPSMModel)}
+ : mCodingSM{std::make_unique<nsCodingStateMachine>(EUCJPSMModel)}
{
}
diff --git a/src/probers/nsEUCKRProber.cpp b/src/probers/nsEUCKRProber.cpp
index 26eafca..080df07 100644
--- a/src/probers/nsEUCKRProber.cpp
+++ b/src/probers/nsEUCKRProber.cpp
@@ -10,7 +10,7 @@
namespace kencodingprober
{
nsEUCKRProber::nsEUCKRProber()
- : mCodingSM{std::make_unique<nsCodingStateMachine>(&EUCKRSMModel)}
+ : mCodingSM{std::make_unique<nsCodingStateMachine>(EUCKRSMModel)}
{
}
diff --git a/src/probers/nsEscCharsetProber.cpp b/src/probers/nsEscCharsetProber.cpp
index 889c585..343d4b5 100644
--- a/src/probers/nsEscCharsetProber.cpp
+++ b/src/probers/nsEscCharsetProber.cpp
@@ -11,8 +11,8 @@ namespace kencodingprober
{
nsEscCharSetProber::nsEscCharSetProber(void)
{
- mCodingSM[0] = std::make_unique<nsCodingStateMachine>(&ISO2022JPSMModel);
- mCodingSM[1] = std::make_unique<nsCodingStateMachine>(&HZSMModel);
+ mCodingSM[0] = std::make_unique<nsCodingStateMachine>(ISO2022JPSMModel);
+ mCodingSM[1] = std::make_unique<nsCodingStateMachine>(HZSMModel);
}
nsEscCharSetProber::~nsEscCharSetProber(void) = default;
diff --git a/src/probers/nsGB2312Prober.cpp b/src/probers/nsGB2312Prober.cpp
index 42cf479..63fd667 100644
--- a/src/probers/nsGB2312Prober.cpp
+++ b/src/probers/nsGB2312Prober.cpp
@@ -15,7 +15,7 @@
namespace kencodingprober
{
nsGB18030Prober::nsGB18030Prober()
- : mCodingSM{std::make_unique<nsCodingStateMachine>(&GB18030SMModel)}
+ : mCodingSM{std::make_unique<nsCodingStateMachine>(GB18030SMModel)}
{
}
diff --git a/src/probers/nsSJISProber.cpp b/src/probers/nsSJISProber.cpp
index e2431de..4ab93d5 100644
--- a/src/probers/nsSJISProber.cpp
+++ b/src/probers/nsSJISProber.cpp
@@ -15,7 +15,7 @@
namespace kencodingprober
{
nsSJISProber::nsSJISProber()
- : mCodingSM{std::make_unique<nsCodingStateMachine>(&SJISSMModel)}
+ : mCodingSM{std::make_unique<nsCodingStateMachine>(SJISSMModel)}
{
}