Skip to content

refactor: use new string type part 1#705

Open
nickvunen wants to merge 1 commit into
masterfrom
refactor-strings
Open

refactor: use new string type part 1#705
nickvunen wants to merge 1 commit into
masterfrom
refactor-strings

Conversation

@nickvunen

Copy link
Copy Markdown
Collaborator

What's done

Foundation (compile-time safety + helpers)

  • Bumped C++ standard to C++20
  • Added __attribute__((format(printf,...))) to CDBDebug, CDBError, CDBWarning, CT::printf, etc. — compiler now rejects %s against a std::string at build time
  • Added 25 free helpers in namespace CT:: operating on std::string (split, trim, replace, printf, startsWith, endsWith, indexOf, toFloat, isFloat, encodeXml, basename, ...)
  • Added CT::fromCStr(const char*) for null-safe const char*std::string conversion (replaces CT::string's null-pointer-tolerant constructor)
  • Added CT::string ↔ std::string interop (constructor + explicit cast)
  • 23 new unit tests, 34 total passing

Migrated to std::string

Fields:

  • GeoParameters::crs
  • ProjectionMapKey::{sourceCRS, destCRS}
  • PointDV::id
  • CRectangleText::{text, fontFile}
  • CServerParams::{responceCrs, mapTitle, mapSubTitle, BGColor, JSONP, queryStrURLParam, datasetLocation}
  • CRequest::{Version, Exceptions}
  • COpenDAPHandler::httpHeaderContentType
  • CNetCDFDataWriter::tempFileName
  • CXMLGen::serviceInfo
  • CReporter::_filename
    Function signatures:
  • isLonLatProjection, isMercatorProjection
  • findReaderByFileName
  • checkIfFileMatchesLayer
  • findLayerConfigForRequestedLayer
  • CSLD::{parameterIsSld, processSLDUrl}
  • CReporter::filename
    Null-safety: .copy(rawCharPtr)= CT::fromCStr(rawCharPtr) across CCDFDataModel/

Bug fixes uncovered by the format attribute

  • CXMLSerializerInterface.cpp:102CT::string passed via %s varargs
  • CCDFNetCDFIO.cpp:552CT::string * passed via %s varargs
  • COpenDAPHandler.cpp:423getenv() null-pointer crash post-migration

Docs

  • NEWS.md updated
  • doc/developing/string-migration.md — patterns + risks for future PRs

Stats

  • 56 files, +765 / −156 lines
  • Unit tests: 34/34 pass
  • Integration tests: 258 pass (was 216 pre-session; foundation fixed 42 previously-failing tests)
  • Same 4 known cross-platform failures remain (proj/cairo anti-aliasing on macOS arm64)

What's left

  • CCDFDataModel domain modelCDF::Variable::name, CDF::Attribute::name, CDF::Dimension::name still CT::string. Touched by every reader/converter; needs a dedicated PR.
  • CDataSource membersnativeProj4, nativeEPSG, headerFilename, meaning, etc. High ripple, needs dedicated PR.
  • Auto-generated XSD layeradagucserverEC/CServerConfig_CPPXSD.h (hundreds of CT::string attribute fields) and the field rename CXMLObjectInterface::valueelementValue. PR Improve cfg parsing #700 has a proposed mechanical rewrite for this.
  • Other large carriersLayerMetadataType.h, CKeyValuePair, COGCDims, CXMLParser::XMLElement, CTime, CDBStore::Record, CXMLGen::* (CT::string *XMLDoc builder pattern).
  • Remaining hclasses/CXMLParser, CDirReader, CHTTPTools, CReportMessage.
  • Final cleanup (Phase 6) — once all callers are migrated:
    • Delete CT::string, CT::stringref, CT::StackList
    • Remove operator const char *() (currently catches printf misuse via the format attribute, but should ultimately be replaced by all callers using .c_str() explicitly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant