From bf1db210d755986e0cdcbff25aa1e88b22355554 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 15 Oct 2021 15:31:06 +0100 Subject: [PATCH] SGMetar: avoid raw char pointers in the public API Ideally would refactor to remove the raw pointers internally, but this is a good first step. --- simgear/environment/metar.cxx | 12 ++++++++++-- simgear/environment/metar.hxx | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/simgear/environment/metar.cxx b/simgear/environment/metar.cxx index c9084730..7ebd3f7c 100644 --- a/simgear/environment/metar.cxx +++ b/simgear/environment/metar.cxx @@ -491,9 +491,17 @@ void SGMetar::useCurrentDate() _month = now.tm_mon + 1; } -const char* SGMetar::getRawDataPtr() +std::string SGMetar::getDataString() const { - return _data.data(); + return std::string{_data.data()}; +} + +std::string SGMetar::getUnparsedData() const +{ + if (!_m || (strlen(_m) < 1)) + return {}; + + return std::string{_m}; } /** * Replace any number of subsequent spaces by just one space, and add diff --git a/simgear/environment/metar.hxx b/simgear/environment/metar.hxx index 50880a10..df90c28c 100644 --- a/simgear/environment/metar.hxx +++ b/simgear/environment/metar.hxx @@ -186,7 +186,8 @@ public: std::vector phenomena; }; - const char* getRawDataPtr(); + std::string getDataString() const; + std::string getUnparsedData() const; inline bool getProxy() const { return _x_proxy; } inline const char *getId() const { return _icao; }