diff --git a/mdflibrary/MdfAttachment.cpp b/mdflibrary/MdfAttachment.cpp index 4f5208fc..de990f61 100644 --- a/mdflibrary/MdfAttachment.cpp +++ b/mdflibrary/MdfAttachment.cpp @@ -20,11 +20,11 @@ Int64 MdfAttachment::Index::get() { return attachment_ != nullptr ? attachment_->Index() : 0; } -unsigned short MdfAttachment::CreatorIndex::get() { +UInt16 MdfAttachment::CreatorIndex::get() { return attachment_ != nullptr ? attachment_->CreatorIndex() : 0; } -void MdfAttachment::CreatorIndex::set(unsigned short index) { +void MdfAttachment::CreatorIndex::set(UInt16 index) { if (attachment_ != nullptr) { attachment_->CreatorIndex(index); } @@ -56,8 +56,8 @@ String^ MdfAttachment::Md5::get() { } return attachment_->Md5().has_value() - ? MdfLibrary::Utf8Conversion( - attachment_->Md5().value()) : gcnew String(""); + ? MdfLibrary::Utf8Conversion(attachment_->Md5().value()) + : gcnew String(""); } String^ MdfAttachment::FileName::get() { @@ -66,10 +66,8 @@ String^ MdfAttachment::FileName::get() { } void MdfAttachment::FileName::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); if (attachment_ != nullptr) { - attachment_->FileName(temp); + attachment_->FileName(MdfLibrary::Utf8Conversion(name)); } } @@ -79,10 +77,8 @@ String^ MdfAttachment::FileType::get() { } void MdfAttachment::FileType::set(String^ type) { - const auto temp = String::IsNullOrEmpty(type) ? - std::string() : marshal_as(type); if (attachment_ != nullptr) { - attachment_->FileType(temp); + attachment_->FileType(MdfLibrary::Utf8Conversion(type)); } } diff --git a/mdflibrary/MdfChannel.cpp b/mdflibrary/MdfChannel.cpp index a8b1adb6..aa67d233 100644 --- a/mdflibrary/MdfChannel.cpp +++ b/mdflibrary/MdfChannel.cpp @@ -21,10 +21,8 @@ String^ MdfChannel::Name::get() { } void MdfChannel::Name::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? std::string() - : marshal_as(name); if (channel_ != nullptr) { - channel_->Name(temp); + channel_->Name(MdfLibrary::Utf8Conversion(name)); } } @@ -35,10 +33,8 @@ String^ MdfChannel::DisplayName::get() { } void MdfChannel::DisplayName::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? std::string() - : marshal_as(name); if (channel_ != nullptr) { - channel_->DisplayName(temp); + channel_->DisplayName(MdfLibrary::Utf8Conversion(name)); } } @@ -49,10 +45,8 @@ String^ MdfChannel::Description::get() { } void MdfChannel::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? std::string() - : marshal_as(desc); if (channel_ != nullptr) { - channel_->Description(temp); + channel_->Description(MdfLibrary::Utf8Conversion(desc)); } } @@ -66,10 +60,8 @@ String^ MdfChannel::Unit::get() { } void MdfChannel::Unit::set(String^ unit) { - const auto temp = String::IsNullOrEmpty(unit) ? std::string() - : marshal_as(unit); if (channel_ != nullptr) { - channel_->Unit(temp); + channel_->Unit(MdfLibrary::Utf8Conversion(unit)); } } @@ -110,7 +102,7 @@ void MdfChannel::DataType::set(ChannelDataType type) { } CnFlag MdfChannel::Flags::get() { - auto temp = channel_ == nullptr ? static_cast(channel_->Flags()) : CnFlag::None; + auto temp = channel_ != nullptr ? static_cast(channel_->Flags()) : CnFlag::None; return temp; } @@ -268,10 +260,8 @@ void MdfChannel::SetChannelValue(const double value, bool valid) { } void MdfChannel::SetChannelValue(String^ value, bool valid) { - const auto temp = String::IsNullOrEmpty(value) - ? std::string() - : marshal_as(value); - if (channel_ != nullptr) channel_->SetChannelValue(temp, valid); + if (channel_ != nullptr) + channel_->SetChannelValue(MdfLibrary::Utf8Conversion(value), valid); } void MdfChannel::SetChannelValue(array^ value, bool valid) { diff --git a/mdflibrary/MdfChannelConversion.cpp b/mdflibrary/MdfChannelConversion.cpp index 4e80d94e..be40abcc 100644 --- a/mdflibrary/MdfChannelConversion.cpp +++ b/mdflibrary/MdfChannelConversion.cpp @@ -21,10 +21,8 @@ String^ MdfChannelConversion::Name::get() { } void MdfChannelConversion::Name::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); if (conversion_ != nullptr) { - conversion_->Name(temp); + conversion_->Name(MdfLibrary::Utf8Conversion(name)); } } @@ -32,10 +30,8 @@ String^ MdfChannelConversion::Description::get() { return conversion_ != nullptr ? MdfLibrary::Utf8Conversion(conversion_->Description()) : gcnew String(""); } void MdfChannelConversion::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); if (conversion_ != nullptr) { - conversion_->Description(temp); + conversion_->Description(MdfLibrary::Utf8Conversion(desc)); } } @@ -48,10 +44,8 @@ String^ MdfChannelConversion::Unit::get() { } void MdfChannelConversion::Unit::set(String^ unit) { - const auto temp = String::IsNullOrEmpty(unit) ? - std::string() : marshal_as(unit); if (conversion_ != nullptr) { - conversion_->Unit(temp); + conversion_->Unit(MdfLibrary::Utf8Conversion(unit)); } } diff --git a/mdflibrary/MdfChannelGroup.cpp b/mdflibrary/MdfChannelGroup.cpp index 62981ee1..bd29c36f 100644 --- a/mdflibrary/MdfChannelGroup.cpp +++ b/mdflibrary/MdfChannelGroup.cpp @@ -30,10 +30,8 @@ String^ MdfChannelGroup::Name::get() { } void MdfChannelGroup::Name::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); if (group_ != nullptr) { - group_->Name(temp); + group_->Name(MdfLibrary::Utf8Conversion(name)); } } @@ -42,10 +40,8 @@ String^ MdfChannelGroup::Description::get() { } void MdfChannelGroup::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); if (group_ != nullptr) { - group_->Description(temp); + group_->Description(MdfLibrary::Utf8Conversion(desc)); } } diff --git a/mdflibrary/MdfDataGroup.cpp b/mdflibrary/MdfDataGroup.cpp index 5ad1a34b..17b2502d 100644 --- a/mdflibrary/MdfDataGroup.cpp +++ b/mdflibrary/MdfDataGroup.cpp @@ -21,10 +21,8 @@ String^ MdfDataGroup::Description::get() { } void MdfDataGroup::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); if (group_ != nullptr) { - group_->Description(temp); + group_->Description(MdfLibrary::Utf8Conversion(desc)); } } diff --git a/mdflibrary/MdfETag.cpp b/mdflibrary/MdfETag.cpp index 44d51114..f10f4aef 100644 --- a/mdflibrary/MdfETag.cpp +++ b/mdflibrary/MdfETag.cpp @@ -29,10 +29,8 @@ String^ MdfETag::Name::get() { } void MdfETag::Name::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); if (tag_ != nullptr) { - tag_->Name(temp); + tag_->Name(MdfLibrary::Utf8Conversion(name)); } } @@ -41,10 +39,8 @@ String^ MdfETag::Description::get() { } void MdfETag::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); if (tag_ != nullptr) { - tag_->Description(temp); + tag_->Description(MdfLibrary::Utf8Conversion(desc)); } } @@ -53,10 +49,8 @@ String^ MdfETag::Unit::get() { } void MdfETag::Unit::set(String^ unit) { - const auto temp = String::IsNullOrEmpty(unit) ? - std::string() : marshal_as(unit); if (tag_ != nullptr) { - tag_->Unit(temp); + tag_->Unit(MdfLibrary::Utf8Conversion(unit)); } } @@ -65,10 +59,8 @@ String^ MdfETag::UnitRef::get() { } void MdfETag::UnitRef::set(String^ unit) { - const auto temp = String::IsNullOrEmpty(unit) ? - std::string() : marshal_as(unit); if (tag_ != nullptr) { - tag_->UnitRef(temp); + tag_->UnitRef(MdfLibrary::Utf8Conversion(unit)); } } @@ -77,10 +69,8 @@ String^ MdfETag::Type::get() { } void MdfETag::Type::set(String^ type) { - const auto temp = String::IsNullOrEmpty(type) ? - std::string() : marshal_as(type); if (tag_ != nullptr) { - tag_->Type(temp); + tag_->Type(MdfLibrary::Utf8Conversion(type)); } } @@ -100,10 +90,8 @@ String^ MdfETag::Language::get() { } void MdfETag::Language::set(String^ language) { - const auto temp = String::IsNullOrEmpty(language) ? - std::string() : marshal_as(language); if (tag_ != nullptr) { - tag_->Language(temp); + tag_->Language(MdfLibrary::Utf8Conversion(language)); } } @@ -122,10 +110,8 @@ String^ MdfETag::ValueAsString::get() { } void MdfETag::ValueAsString::set(String^ value) { - const auto temp = String::IsNullOrEmpty(value) ? - std::string() : marshal_as(value); if (tag_ != nullptr) { - tag_->Value(temp); + tag_->Value(MdfLibrary::Utf8Conversion(value)); } } diff --git a/mdflibrary/MdfEvent.cpp b/mdflibrary/MdfEvent.cpp index 2c0ba00b..7fbc29c5 100644 --- a/mdflibrary/MdfEvent.cpp +++ b/mdflibrary/MdfEvent.cpp @@ -21,10 +21,8 @@ String^ MdfEvent::Name::get() { } void MdfEvent::Name::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); if (event_ != nullptr) { - event_->Name(temp); + event_->Name(MdfLibrary::Utf8Conversion(name)); } } @@ -33,10 +31,8 @@ String^ MdfEvent::Description::get() { } void MdfEvent::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); if (event_ != nullptr) { - event_->Description(temp); + event_->Description(MdfLibrary::Utf8Conversion(desc)); } } @@ -45,11 +41,8 @@ String ^ MdfEvent::GroupName::get() { } void MdfEvent::GroupName::set(String ^ group_name) { - const auto temp = String::IsNullOrEmpty(group_name) - ? std::string() - : marshal_as(group_name); - if (event_ != nullptr) { - event_->GroupName(temp); +if (event_ != nullptr) { + event_->GroupName(MdfLibrary::Utf8Conversion(group_name)); } } diff --git a/mdflibrary/MdfFile.cpp b/mdflibrary/MdfFile.cpp index a1ea9099..486a1103 100644 --- a/mdflibrary/MdfFile.cpp +++ b/mdflibrary/MdfFile.cpp @@ -46,10 +46,8 @@ String^ MdfFile::Name::get() { } void MdfFile::Name::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); if (mdf_file_ != nullptr) { - mdf_file_->Name(temp); + mdf_file_->Name(MdfLibrary::Utf8Conversion(name)); } } @@ -59,10 +57,8 @@ String^ MdfFile::Filename::get() { } void MdfFile::Filename::set(String^ filename) { - const auto temp = String::IsNullOrEmpty(filename) ? - std::string() : marshal_as(filename); if (mdf_file_ != nullptr) { - mdf_file_->FileName(temp); + mdf_file_->FileName(MdfLibrary::Utf8Conversion(filename)); } } @@ -90,10 +86,8 @@ String^ MdfFile::ProgramId::get() { } void MdfFile::ProgramId::set(String^ program_id) { - const auto temp = String::IsNullOrEmpty(program_id) ? - std::string() : marshal_as(program_id); if (mdf_file_ != nullptr) { - mdf_file_->ProgramId(temp); + mdf_file_->ProgramId(MdfLibrary::Utf8Conversion(program_id)); } } diff --git a/mdflibrary/MdfFileHistory.cpp b/mdflibrary/MdfFileHistory.cpp index 754ff0be..fce5cbdf 100644 --- a/mdflibrary/MdfFileHistory.cpp +++ b/mdflibrary/MdfFileHistory.cpp @@ -37,10 +37,8 @@ String^ MdfFileHistory::Description::get() { } void MdfFileHistory::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); if (history_ != nullptr) { - history_->Description(temp); + history_->Description(MdfLibrary::Utf8Conversion(desc)); } } @@ -49,10 +47,8 @@ String^ MdfFileHistory::ToolName::get() { } void MdfFileHistory::ToolName::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); - if (history_ != nullptr) { - history_->ToolName(temp); +if (history_ != nullptr) { + history_->ToolName(MdfLibrary::Utf8Conversion(name)); } } @@ -63,10 +59,8 @@ String^ MdfFileHistory::ToolVendor::get() { } void MdfFileHistory::ToolVendor::set(String^ vendor) { - const auto temp = String::IsNullOrEmpty(vendor) ? - std::string() : marshal_as(vendor); - if (history_ != nullptr) { - history_->ToolVendor(temp); +if (history_ != nullptr) { + history_->ToolVendor(MdfLibrary::Utf8Conversion(vendor)); } } @@ -77,10 +71,8 @@ String^ MdfFileHistory::ToolVersion::get() { } void MdfFileHistory::ToolVersion::set(String^ version) { - const auto temp = String::IsNullOrEmpty(version) ? - std::string() : marshal_as(version); - if (history_ != nullptr) { - history_->ToolVersion(temp); +if (history_ != nullptr) { + history_->ToolVersion(MdfLibrary::Utf8Conversion(version)); } } @@ -91,10 +83,8 @@ String^ MdfFileHistory::UserName::get() { } void MdfFileHistory::UserName::set(String^ user) { - const auto temp = String::IsNullOrEmpty(user) ? - std::string() : marshal_as(user); if (history_ != nullptr) { - history_->UserName(marshal_as(user)); + history_->UserName(MdfLibrary::Utf8Conversion(user)); } } diff --git a/mdflibrary/MdfHeader.cpp b/mdflibrary/MdfHeader.cpp index 4b7b6e61..0c151a22 100644 --- a/mdflibrary/MdfHeader.cpp +++ b/mdflibrary/MdfHeader.cpp @@ -24,10 +24,8 @@ String^ MdfHeader::Description::get() { } void MdfHeader::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); - if (header_ != nullptr) { - header_->Description(temp); +if (header_ != nullptr) { + header_->Description(MdfLibrary::Utf8Conversion(desc)); } } @@ -36,10 +34,8 @@ String^ MdfHeader::Author::get() { } void MdfHeader::Author::set(String^ author) { - const auto temp = String::IsNullOrEmpty(author) ? - std::string() : marshal_as(author); - if (header_ != nullptr) { - header_->Author(temp); +if (header_ != nullptr) { + header_->Author(MdfLibrary::Utf8Conversion(author)); } } @@ -48,10 +44,8 @@ String^ MdfHeader::Department::get() { } void MdfHeader::Department::set(String^ department) { - const auto temp = String::IsNullOrEmpty(department) ? - std::string() : marshal_as(department); - if (header_ != nullptr) { - header_->Department(temp); +if (header_ != nullptr) { + header_->Department(MdfLibrary::Utf8Conversion(department)); } } @@ -61,8 +55,7 @@ String^ MdfHeader::Project::get() { void MdfHeader::Project::set(String^ project) { if (header_ != nullptr) { - header_->Project(String::IsNullOrEmpty(project) ? - std::string() : marshal_as(project)); + header_->Project(MdfLibrary::Utf8Conversion(project)); } } @@ -72,8 +65,7 @@ String^ MdfHeader::Subject::get() { void MdfHeader::Subject::set(String^ subject) { if (header_ != nullptr) { - header_->Subject(String::IsNullOrEmpty(subject) ? - std::string() : marshal_as(subject)); + header_->Subject(MdfLibrary::Utf8Conversion(subject)); } } @@ -83,8 +75,7 @@ String^ MdfHeader::MeasurementId::get() { void MdfHeader::MeasurementId::set(String^ uuid) { if (header_ != nullptr) { - header_->MeasurementId(String::IsNullOrEmpty(uuid) ? - std::string() : marshal_as(uuid)); + header_->MeasurementId(MdfLibrary::Utf8Conversion(uuid)); } } @@ -94,8 +85,7 @@ String^ MdfHeader::RecorderId::get() { void MdfHeader::RecorderId::set(String^ uuid) { if (header_ != nullptr) { - header_->RecorderId(String::IsNullOrEmpty(uuid) ? - std::string() : marshal_as(uuid)); + header_->RecorderId(MdfLibrary::Utf8Conversion(uuid)); } } diff --git a/mdflibrary/MdfMetaData.cpp b/mdflibrary/MdfMetaData.cpp index 6ab62dc2..4cb5b50a 100644 --- a/mdflibrary/MdfMetaData.cpp +++ b/mdflibrary/MdfMetaData.cpp @@ -13,37 +13,26 @@ using namespace msclr::interop; namespace MdfLibrary { String^ MdfMetaData::PropertyAsString::get(String^ index) { - const auto key = String::IsNullOrEmpty(index) ? - std::string() : marshal_as(index); return meta_data_ != nullptr ? MdfLibrary::Utf8Conversion( - meta_data_->StringProperty(key)) : gcnew String(""); + meta_data_->StringProperty(MdfLibrary::Utf8Conversion(index))) : gcnew String(""); } void MdfMetaData::PropertyAsString::set(String^ index, String^ prop) { - if (String::IsNullOrEmpty(index)) { - return; - } - const auto key = marshal_as(index); - const auto value = String::IsNullOrEmpty(prop) ? - std::string() : marshal_as(prop); if (meta_data_ != nullptr) { - meta_data_->StringProperty(key, value); + meta_data_->StringProperty(MdfLibrary::Utf8Conversion(index), + MdfLibrary::Utf8Conversion(prop)); } } double MdfMetaData::PropertyAsFloat::get(String^ index) { - const auto key = String::IsNullOrEmpty(index) ? - std::string() : marshal_as(index); - return meta_data_ != nullptr ? meta_data_->FloatProperty(key) : 0.0; + return meta_data_ != nullptr + ? meta_data_->FloatProperty(MdfLibrary::Utf8Conversion(index)) + : 0.0; } void MdfMetaData::PropertyAsFloat::set(String^ index, double prop) { - if (String::IsNullOrEmpty(index)) { - return; - } - const auto key = marshal_as(index); if (meta_data_ != nullptr) { - meta_data_->FloatProperty(key, prop); + meta_data_->FloatProperty(MdfLibrary::Utf8Conversion(index), prop); } } @@ -92,18 +81,16 @@ String^ MdfMetaData::XmlSnippet::get() { } void MdfMetaData::XmlSnippet::set(String^ xml) { - const auto temp = String::IsNullOrEmpty(xml) ? - std::string() : marshal_as(xml); - if (meta_data_ != nullptr) { - meta_data_->XmlSnippet(temp); +if (meta_data_ != nullptr) { + meta_data_->XmlSnippet(MdfLibrary::Utf8Conversion(xml)); } } MdfETag^ MdfMetaData::GetCommonProperty(String^ name) { - const auto key = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); - const auto temp = meta_data_ != nullptr ? - meta_data_->CommonProperty(key) : mdf::ETag(); + const auto temp = + meta_data_ != nullptr + ? meta_data_->CommonProperty(MdfLibrary::Utf8Conversion(name)) + : mdf::ETag(); return gcnew MdfETag(temp); } diff --git a/mdflibrary/MdfReader.cpp b/mdflibrary/MdfReader.cpp index a106155f..4363db7e 100644 --- a/mdflibrary/MdfReader.cpp +++ b/mdflibrary/MdfReader.cpp @@ -14,7 +14,7 @@ using namespace msclr::interop; namespace MdfLibrary { MdfReader::MdfReader(String^ filename) { - reader_ = new mdf::MdfReader(marshal_as(filename)); + reader_ = new mdf::MdfReader(MdfLibrary::Utf8Conversion(filename)); } diff --git a/mdflibrary/MdfSourceInformation.cpp b/mdflibrary/MdfSourceInformation.cpp index 7c18ef60..87aa7493 100644 --- a/mdflibrary/MdfSourceInformation.cpp +++ b/mdflibrary/MdfSourceInformation.cpp @@ -21,10 +21,8 @@ String^ MdfSourceInformation::Name::get() { } void MdfSourceInformation::Name::set(String^ name) { - const auto temp = String::IsNullOrEmpty(name) ? - std::string() : marshal_as(name); if (info_ != nullptr) { - info_->Name(temp); + info_->Name(MdfLibrary::Utf8Conversion(name)); } } String^ MdfSourceInformation::Description::get() { @@ -32,10 +30,8 @@ String^ MdfSourceInformation::Description::get() { } void MdfSourceInformation::Description::set(String^ desc) { - const auto temp = String::IsNullOrEmpty(desc) ? - std::string() : marshal_as(desc); - if (info_ != nullptr) { - info_->Description(temp); +if (info_ != nullptr) { + info_->Description(MdfLibrary::Utf8Conversion(desc)); } } @@ -44,10 +40,8 @@ String^ MdfSourceInformation::Path::get() { } void MdfSourceInformation::Path::set(String^ path) { - const auto temp = String::IsNullOrEmpty(path) ? - std::string() : marshal_as(path); - if (info_ != nullptr) { - info_->Path(temp); +if (info_ != nullptr) { + info_->Path(MdfLibrary::Utf8Conversion(path)); } } diff --git a/mdflibrary/MdfWriter.cpp b/mdflibrary/MdfWriter.cpp index 039bc676..65511ea3 100644 --- a/mdflibrary/MdfWriter.cpp +++ b/mdflibrary/MdfWriter.cpp @@ -55,10 +55,7 @@ bool MdfWriter::CompressData::get() { } bool MdfWriter::Init(String^ path_name) { - const auto temp = String::IsNullOrEmpty(path_name) - ? std::string() - : marshal_as(path_name); - return writer_->Init(temp); + return writer_->Init(MdfLibrary::Utf8Conversion(path_name)); } MdfDataGroup^ MdfWriter::CreateDataGroup() { diff --git a/mdflibrary/mdflibrary.cpp b/mdflibrary/mdflibrary.cpp index ca43c2d0..1a18793f 100644 --- a/mdflibrary/mdflibrary.cpp +++ b/mdflibrary/mdflibrary.cpp @@ -51,8 +51,7 @@ MdfLibrary^ MdfLibrary::Instance::get() { } bool MdfLibrary::IsMdfFile(String^ filename) { - return String::IsNullOrEmpty(filename) ? - false : mdf::IsMdfFile(marshal_as(filename)); + return mdf::IsMdfFile(MdfLibrary::Utf8Conversion(filename)); } MdfChannelObserver^ MdfLibrary::CreateChannelObserver(MdfDataGroup^ data_group, @@ -84,7 +83,7 @@ MdfChannelObserver^ MdfLibrary::CreateChannelObserverByChannelName( return nullptr; } auto observer = mdf::CreateChannelObserver(*data_group->group_, - marshal_as(channel_name)); + Utf8Conversion(channel_name)); if (!observer) { return nullptr; } @@ -119,6 +118,15 @@ String^ MdfLibrary::Utf8Conversion(const std::string& utf8_string) { return u8enc->GetString(c_array); } +std::string MdfLibrary::Utf8Conversion(String^ string) { + array^ c_array = System::Text::Encoding::UTF8->GetBytes(string); + + std::string utf8_string; + utf8_string.resize(c_array->Length); + for (int i = 0; i < c_array->Length; i++) utf8_string[i] = c_array[i]; + return utf8_string; +} + void MdfLibrary::FireLogEvent(MdfLogSeverity severity, String^ function, String^ message) { LogEvent(severity, function, message); diff --git a/mdflibrary/mdflibrary.h b/mdflibrary/mdflibrary.h index c0a8f1a7..a1cf65b1 100644 --- a/mdflibrary/mdflibrary.h +++ b/mdflibrary/mdflibrary.h @@ -47,6 +47,7 @@ public ref class MdfLibrary { MdfChannelGroup^ channel_group); static String^ Utf8Conversion(const std::string& utf8_string); + static std::string MdfLibrary::Utf8Conversion(String ^ string); event DoLogEvent^ LogEvent; protected: diff --git a/mdflibrary_test/MdfLibraryTest.cs b/mdflibrary_test/MdfLibraryTest.cs index 0b2256aa..fa405720 100644 --- a/mdflibrary_test/MdfLibraryTest.cs +++ b/mdflibrary_test/MdfLibraryTest.cs @@ -546,6 +546,7 @@ public void TestWriter() var cn = cg.CreateChannel(); cn.Name = "UnsignedLe"; cn.Description = "uint32_t"; + cn.Unit = "°C"; cn.Type = ChannelType.FixedLength; cn.DataType = ChannelDataType.UnsignedIntegerLe; cn.DataBytes = 4;