diff --git a/indra/llcommon/llsdutil.cpp b/indra/llcommon/llsdutil.cpp index ac86f4ff6f..efc95c3e3a 100644 --- a/indra/llcommon/llsdutil.cpp +++ b/indra/llcommon/llsdutil.cpp @@ -46,6 +46,8 @@ #include #include #include +#include +#include // Suppress warnings about the string fiddling #if LL_LINUX @@ -205,6 +207,39 @@ std::string ll_stream_notation_sd(const LLSD& sd) return stream.str(); } +// Create LLSD from CSV +LLSD ll_sd_from_csv(std::istream& csv, std::string_view delimiters) +{ + LLSD data; + bool headerRead{ false }; + std::vector columnNames; + std::string line; + + while (std::getline(csv, line)) + { + std::vector columns; + boost::split(columns, line, boost::is_any_of(delimiters)); + + if (!headerRead) + { + headerRead = true; + columnNames = std::move(columns); + } + else + { + LLSD rowData; + for (size_t i = 0; i < columnNames.size() && i < columns.size(); ++i) + { + rowData[columnNames.at(i)] = columns.at(i); + } + + data.append(rowData); + } + } + + return data; +} +// //compares the structure of an LLSD to a template LLSD and stores the //"valid" values in a 3rd LLSD. Default values pulled from the template diff --git a/indra/llcommon/llsdutil.h b/indra/llcommon/llsdutil.h index 38bbe19ddd..2eb6ab3c68 100644 --- a/indra/llcommon/llsdutil.h +++ b/indra/llcommon/llsdutil.h @@ -65,6 +65,9 @@ LL_COMMON_API char* ll_pretty_print_sd(const LLSD& sd); LL_COMMON_API std::string ll_stream_notation_sd(const LLSD& sd); +// Create LLSD from CSV +LL_COMMON_API LLSD ll_sd_from_csv(std::istream& csv, std::string_view delimiters = ","); + //compares the structure of an LLSD to a template LLSD and stores the //"valid" values in a 3rd LLSD. Default values //are pulled from the template. Extra keys/values in the test diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp index 16016d7aaa..c114618217 100644 --- a/indra/llui/llscrolllistctrl.cpp +++ b/indra/llui/llscrolllistctrl.cpp @@ -431,7 +431,7 @@ bool LLScrollListCtrl::setMaxItemCount(S32 max_count) } // -S32 LLScrollListCtrl::getMaxItemCount() +S32 LLScrollListCtrl::getMaxItemCount() const { return mMaxItemCount; } diff --git a/indra/llui/llscrolllistctrl.h b/indra/llui/llscrolllistctrl.h index 716556f614..b691865f6d 100644 --- a/indra/llui/llscrolllistctrl.h +++ b/indra/llui/llscrolllistctrl.h @@ -214,7 +214,7 @@ public: // returns false if unable to set the max count so low bool setMaxItemCount(S32 max_count); - S32 getMaxItemCount(); // + S32 getMaxItemCount() const; // bool selectByID( const LLUUID& id ); // false if item not found diff --git a/indra/newview/llfloaterland.cpp b/indra/newview/llfloaterland.cpp index 3839fb6cde..483a861f3b 100644 --- a/indra/newview/llfloaterland.cpp +++ b/indra/newview/llfloaterland.cpp @@ -3395,24 +3395,19 @@ void LLPanelLandAccess::importListCallback(LLNameListCtrl* list, const std::vect return; } - std::string line; - std::vector uuids; + uuid_vec_t uuids; + LLSD csvData = ll_sd_from_csv(file); + file.close(); - while (std::getline(file, line)) + for (const auto& entry : llsd::inArray(csvData)) { - LLStringUtil::trim(line); - if (line.empty()) + if (entry.has("UUID")) { - continue; - } - - LLUUID uuid; - if (uuid.set(line)) - { - uuids.push_back(uuid); + LLUUID id{ entry["UUID"].asUUID() }; + if (id.notNull()) + uuids.push_back(std::move(id)); } } - file.close(); if (uuids.empty()) { diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp index e3aead4883..85047b43f2 100644 --- a/indra/newview/llfloaterregioninfo.cpp +++ b/indra/newview/llfloaterregioninfo.cpp @@ -4767,24 +4767,19 @@ void LLPanelEstateAccess::importListCallback(LLNameListCtrl* list, const std::ve return; } - std::string line; - std::vector uuids; + uuid_vec_t uuids; + LLSD csvData = ll_sd_from_csv(file); + file.close(); - while (std::getline(file, line)) + for (const auto& entry : llsd::inArray(csvData)) { - LLStringUtil::trim(line); - if (line.empty()) + if (entry.has("UUID")) { - continue; - } - - LLUUID uuid; - if (uuid.set(line)) - { - uuids.push_back(uuid); + LLUUID id{ entry["UUID"].asUUID() }; + if (id.notNull()) + uuids.push_back(std::move(id)); } } - file.close(); if (uuids.empty()) {