You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ba...@apache.org on 2019/11/11 13:25:45 UTC
[nifi-minifi-cpp] branch master updated: MINIFICPP-1080 - Unicode
conversion fixes and speedup
This is an automated email from the ASF dual-hosted git repository.
bakaid pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new e7b1217 MINIFICPP-1080 - Unicode conversion fixes and speedup
e7b1217 is described below
commit e7b121793d71e1cd3713593041c3978138908033
Author: Daniel Bakai <ba...@apache.org>
AuthorDate: Fri Oct 11 09:30:21 2019 +0000
MINIFICPP-1080 - Unicode conversion fixes and speedup
Signed-off-by: Daniel Bakai <ba...@apache.org>
Approved by aboda on GH
This closes #678
---
.../windows-event-log/ConsumeWindowsEventLog.cpp | 10 ++----
.../windows-event-log/wel/UnicodeConversion.h | 41 ++++++++++++++++++++++
.../windows-event-log/wel/WindowsEventLog.cpp | 5 ++-
3 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp
index 09154ae..54856db 100644
--- a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp
+++ b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp
@@ -29,8 +29,10 @@
#include <iostream>
#include <memory>
#include <regex>
+
#include "wel/MetadataWalker.h"
#include "wel/XMLString.h"
+#include "wel/UnicodeConversion.h"
#include "io/DataStream.h"
#include "core/ProcessContext.h"
@@ -46,12 +48,6 @@ namespace nifi {
namespace minifi {
namespace processors {
-
-
-static std::string to_string(const wchar_t* pChar) {
- return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(pChar);
-}
-
const std::string ConsumeWindowsEventLog::ProcessorName("ConsumeWindowsEventLog");
core::Property ConsumeWindowsEventLog::Channel(
@@ -296,7 +292,7 @@ bool ConsumeWindowsEventLog::subscribe(const std::shared_ptr<core::ProcessContex
size = used;
std::vector<wchar_t> buf(size/2 + 1);
if (EvtRender(NULL, eventHandle, EvtRenderEventXml, size, &buf[0], &used, &propertyCount)) {
- std::string xml = to_string(&buf[0]);
+ std::string xml = wel::to_string(&buf[0]);
EventRender renderedData;
diff --git a/extensions/windows-event-log/wel/UnicodeConversion.h b/extensions/windows-event-log/wel/UnicodeConversion.h
new file mode 100644
index 0000000..01c48bc
--- /dev/null
+++ b/extensions/windows-event-log/wel/UnicodeConversion.h
@@ -0,0 +1,41 @@
+/**
+ * @file UnicodeConversion.h
+ * Unicode conversion functions
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+#include <atlbase.h>
+#include <atlconv.h>
+
+namespace org {
+ namespace apache {
+ namespace nifi {
+ namespace minifi {
+ namespace wel {
+ inline std::string to_string(const wchar_t* pChar) {
+ ATL::CW2A aString(pChar, CP_UTF8);
+ return std::string(aString);
+ }
+ } /* namespace wel */
+ } /* namespace minifi */
+ } /* namespace nifi */
+ } /* namespace apache */
+} /* namespace org */
diff --git a/extensions/windows-event-log/wel/WindowsEventLog.cpp b/extensions/windows-event-log/wel/WindowsEventLog.cpp
index e75675a..7927f3d 100644
--- a/extensions/windows-event-log/wel/WindowsEventLog.cpp
+++ b/extensions/windows-event-log/wel/WindowsEventLog.cpp
@@ -17,6 +17,7 @@
*/
#include <winmeta.h>
#include "WindowsEventLog.h"
+#include "UnicodeConversion.h"
#include "utils/Deleters.h"
#include <algorithm>
@@ -146,9 +147,7 @@ std::string WindowsEventLogHandler::getEventMessage(EVT_HANDLE eventHandle) cons
}
// convert wstring to std::string
- std::wstring message(pBuffer.get());
-
- return std::string(message.begin(), message.end());
+ return to_string(pBuffer.get());
}
void WindowsEventLogHeader::setDelimiter(const std::string &delim) {