diff --git a/src/plugins/streamers/cif/lay_plugin/lay_plugin.pro b/src/plugins/streamers/cif/lay_plugin/lay_plugin.pro index 9bb389f2f..50fdbbf03 100644 --- a/src/plugins/streamers/cif/lay_plugin/lay_plugin.pro +++ b/src/plugins/streamers/cif/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = cif +TARGET = cif_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/streamers/common/lay_plugin/lay_plugin.pro b/src/plugins/streamers/common/lay_plugin/lay_plugin.pro index 835956be0..14f38d0f6 100644 --- a/src/plugins/streamers/common/lay_plugin/lay_plugin.pro +++ b/src/plugins/streamers/common/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = common +TARGET = common_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/streamers/dxf/lay_plugin/lay_plugin.pro b/src/plugins/streamers/dxf/lay_plugin/lay_plugin.pro index 41b33ff9b..9668c260c 100644 --- a/src/plugins/streamers/dxf/lay_plugin/lay_plugin.pro +++ b/src/plugins/streamers/dxf/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = dxf +TARGET = dxf_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/streamers/gds2/lay_plugin/lay_plugin.pro b/src/plugins/streamers/gds2/lay_plugin/lay_plugin.pro index 2b0691531..2d4701f42 100644 --- a/src/plugins/streamers/gds2/lay_plugin/lay_plugin.pro +++ b/src/plugins/streamers/gds2/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = gds2 +TARGET = gds2_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/streamers/lefdef/lay_plugin/lay_plugin.pro b/src/plugins/streamers/lefdef/lay_plugin/lay_plugin.pro index c38a954f5..d74348733 100644 --- a/src/plugins/streamers/lefdef/lay_plugin/lay_plugin.pro +++ b/src/plugins/streamers/lefdef/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = lefdef +TARGET = lefdef_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/streamers/oasis/lay_plugin/lay_plugin.pro b/src/plugins/streamers/oasis/lay_plugin/lay_plugin.pro index 6b793802b..666291b59 100644 --- a/src/plugins/streamers/oasis/lay_plugin/lay_plugin.pro +++ b/src/plugins/streamers/oasis/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = oasis +TARGET = oasis_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/streamers/pcb/lay_plugin/lay_plugin.pro b/src/plugins/streamers/pcb/lay_plugin/lay_plugin.pro index 7109fbd89..ab0ae34cc 100644 --- a/src/plugins/streamers/pcb/lay_plugin/lay_plugin.pro +++ b/src/plugins/streamers/pcb/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = pcb +TARGET = pcb_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/tools/bool/lay_plugin/lay_plugin.pro b/src/plugins/tools/bool/lay_plugin/lay_plugin.pro index cb6587ca3..a052835dd 100644 --- a/src/plugins/tools/bool/lay_plugin/lay_plugin.pro +++ b/src/plugins/tools/bool/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = bool +TARGET = bool_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/tools/diff/lay_plugin/lay_plugin.pro b/src/plugins/tools/diff/lay_plugin/lay_plugin.pro index b1bd29f5e..cf3c0b8c4 100644 --- a/src/plugins/tools/diff/lay_plugin/lay_plugin.pro +++ b/src/plugins/tools/diff/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = diff +TARGET = diff_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/tools/import/lay_plugin/lay_plugin.pro b/src/plugins/tools/import/lay_plugin/lay_plugin.pro index e4aa4df18..c68e0d035 100644 --- a/src/plugins/tools/import/lay_plugin/lay_plugin.pro +++ b/src/plugins/tools/import/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = import +TARGET = import_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/tools/net_tracer/lay_plugin/lay_plugin.pro b/src/plugins/tools/net_tracer/lay_plugin/lay_plugin.pro index 25116b7f4..7f05e1cc4 100644 --- a/src/plugins/tools/net_tracer/lay_plugin/lay_plugin.pro +++ b/src/plugins/tools/net_tracer/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = net_tracer +TARGET = net_tracer_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/plugins/tools/xor/lay_plugin/lay_plugin.pro b/src/plugins/tools/xor/lay_plugin/lay_plugin.pro index 335200947..34dfbf9ec 100644 --- a/src/plugins/tools/xor/lay_plugin/lay_plugin.pro +++ b/src/plugins/tools/xor/lay_plugin/lay_plugin.pro @@ -1,5 +1,5 @@ -TARGET = xor +TARGET = xor_ui DESTDIR = $$OUT_PWD/../../../../lay_plugins include($$PWD/../../../lay_plugin.pri) diff --git a/src/tl/tl/tlFileUtils.cc b/src/tl/tl/tlFileUtils.cc index 9ad1da75e..a9f309e6d 100644 --- a/src/tl/tl/tlFileUtils.cc +++ b/src/tl/tl/tlFileUtils.cc @@ -51,16 +51,16 @@ static std::string trimmed_part (const std::string &part) const char *cp = part.c_str (); #if defined(_WIN32) - while (*cp && *cp != '\\' && *cp != '/') { + while (*cp == '\\' || *cp == '/') { ++cp; } #else - while (*cp && *cp != '/') { + while (*cp == '/') { ++cp; } #endif - return std::string (part, 0, cp - part.c_str ()); + return std::string (cp); } static bool is_part_with_separator (const std::string &part) @@ -108,11 +108,15 @@ std::vector split_path (const std::string &p) while (*cp && (!any || (*cp != '\\' && *cp != '/'))) { if (*cp != '\\' && *cp != '/') { any = true; + } else { + cp0 = cp; } ++cp; } - parts.push_back (std::string (cp0, 0, cp - cp0)); + if (any) { + parts.push_back (std::string (cp0, 0, cp - cp0)); + } } @@ -126,6 +130,8 @@ std::vector split_path (const std::string &p) while (*cp && (!any || *cp != '/')) { if (*cp != '/') { any = true; + } else { + cp0 = cp; } // backslash escape if (*cp == '\\' && cp[1]) { @@ -134,7 +140,9 @@ std::vector split_path (const std::string &p) ++cp; } - parts.push_back (std::string (cp0, 0, cp - cp0)); + if (any) { + parts.push_back (std::string (cp0, 0, cp - cp0)); + } } @@ -254,9 +262,9 @@ std::vector dir_entries (const std::string &s, bool with_files, boo bool mkdir (const std::string &path) { #if defined(_WIN32) - return _wunlink (tl::to_wstring (path).c_str ()) == 0; + return _wmkdir (tl::to_wstring (path).c_str ()) == 0; #else - return unlink (tl::to_local (path).c_str ()) == 0; + return ::mkdir (tl::to_local (path).c_str (), 0777) == 0; #endif } @@ -600,13 +608,22 @@ std::string relative_path (const std::string &base, const std::string &p) return p; } +std::string normalize_path (const std::string &s) +{ + return tl::join (tl::split_path (s), ""); +} + std::string combine_path (const std::string &p1, const std::string &p2) { + if (p2.empty ()) { + return p1; + } else { #if defined(_WIN32) - return p1 + "\\" + p2; + return p1 + "\\" + p2; #else - return p1 + "/" + p2; + return p1 + "/" + p2; #endif + } } bool is_same_file (const std::string &a, const std::string &b) diff --git a/src/tl/tl/tlFileUtils.h b/src/tl/tl/tlFileUtils.h index 324d4c67e..cb8e0db80 100644 --- a/src/tl/tl/tlFileUtils.h +++ b/src/tl/tl/tlFileUtils.h @@ -131,6 +131,13 @@ bool TL_PUBLIC is_same_file (const std::string &a, const std::string &b); */ std::string TL_PUBLIC relative_path (const std::string &base, const std::string &p); +/** + * @brief Normalizes the path + * This function will remove duplicate "/" or "\" and strip any trailing + * "/" or "\". + */ +std::string TL_PUBLIC normalize_path (const std::string &s); + /** * @brief Combines the two path components into one path */ diff --git a/src/tl/tl/tlString.cc b/src/tl/tl/tlString.cc index 3fa91a8f6..84488aecf 100644 --- a/src/tl/tl/tlString.cc +++ b/src/tl/tl/tlString.cc @@ -52,17 +52,17 @@ std::wstring to_wstring (const std::string &s) uint32_t c32 = (unsigned char) *cp++; if (c32 >= 0xf0 && cp + 2 < cpe) { - c32 = (c32 << 18) | ((uint32_t (cp [0]) & 0x3f) << 12) | ((uint32_t (cp [1]) & 0x3f) << 6) | (uint32_t (cp [2]) & 0x3f); + c32 = ((c32 & 0x7) << 18) | ((uint32_t (cp [0]) & 0x3f) << 12) | ((uint32_t (cp [1]) & 0x3f) << 6) | (uint32_t (cp [2]) & 0x3f); cp += 3; } else if (c32 >= 0xe0 && cp + 1 < cpe) { - c32 = (c32 << 12) | ((uint32_t (cp [0]) & 0x3f) << 6) | (uint32_t (cp [1]) & 0x3f); + c32 = ((c32 & 0xf) << 12) | ((uint32_t (cp [0]) & 0x3f) << 6) | (uint32_t (cp [1]) & 0x3f); cp += 2; } else if (c32 >= 0xc0 && cp < cpe) { - c32 = (c32 << 6) | (uint32_t (*cp) & 0x3f); + c32 = ((c32 & 0x1f) << 6) | (uint32_t (*cp) & 0x3f); ++cp; } - if (c32 >= 0x10000) { + if (sizeof (wchar_t) == 2 && c32 >= 0x10000) { c32 -= 0x10000; ws += wchar_t (0xd800 + (c32 >> 10)); ws += wchar_t (0xdc00 + (c32 & 0x3ff)); @@ -82,7 +82,7 @@ std::string to_string (const std::wstring &ws) for (std::wstring::const_iterator c = ws.begin (); c != ws.end (); ++c) { uint32_t c32 = *c; - if (c32 >= 0xd800 && c + 1 < ws.end ()) { + if (sizeof (wchar_t) == 2 && c32 >= 0xd800 && c + 1 < ws.end ()) { ++c; c32 = (c32 & 0x3ff) << 10; c32 |= uint32_t (*c) & 0x3ff; @@ -97,13 +97,13 @@ std::string to_string (const std::wstring &ws) } else if (c32 >= 0x800) { - s.push_back (0xf0 | ((c32 >> 12) & 0xf)); + s.push_back (0xe0 | ((c32 >> 12) & 0xf)); s.push_back (0x80 | ((c32 >> 6) & 0x3f)); s.push_back (0x80 | (c32 & 0x3f)); } else if (c32 >= 0x80) { - s.push_back (0xf0 | ((c32 >> 6) & 0xc)); + s.push_back (0xc0 | ((c32 >> 6) & 0x1f)); s.push_back (0x80 | (c32 & 0x3f)); } else { diff --git a/src/tl/tl/tlThreads.h b/src/tl/tl/tlThreads.h index 505846b7c..89a5f32fd 100644 --- a/src/tl/tl/tlThreads.h +++ b/src/tl/tl/tlThreads.h @@ -163,14 +163,14 @@ protected: * available. */ -#if defined(HVE_QT) +#if defined(HAVE_QT) template class TL_PUBLIC ThreadStorage : public QThreadStorage { public: - ThreadStorage () : QThreadStorage () { } + ThreadStorage () : QThreadStorage () { } }; #else @@ -180,15 +180,16 @@ template class TL_PUBLIC ThreadStorage { public: - ThreadStorage () : m_t () { } + ThreadStorage () : m_t (), m_has_data (false) { } - bool hasLocalData () const { return true; } + bool hasLocalData () const { return m_has_data; } T &localData () { return m_t; } T localData () const { return m_t; } - void setLocalData (T data) { m_t = data; } + void setLocalData (const T &data) { m_t = data; m_has_data = true; } private: T m_t; + bool m_has_data; }; #endif diff --git a/src/tl/tl/tlTimer.cc b/src/tl/tl/tlTimer.cc index b3b86ded3..de3181891 100644 --- a/src/tl/tl/tlTimer.cc +++ b/src/tl/tl/tlTimer.cc @@ -79,7 +79,7 @@ Timer::start () struct timespec spec; clock_gettime (CLOCK_REALTIME, &spec); - m_wall_ms = ms_time (); + m_wall_ms += ms_time (); } void diff --git a/src/tl/unit_tests/tlString.cc b/src/tl/unit_tests/tlString.cc index 490645d67..ee7a09bf8 100644 --- a/src/tl/unit_tests/tlString.cc +++ b/src/tl/unit_tests/tlString.cc @@ -479,3 +479,17 @@ TEST(14) EXPECT_EQ (pad_string_left (6, "abc"), " abc"); EXPECT_EQ (pad_string_left (4, ""), " "); } + +// UTF-8 to wchar_t and local conversion +TEST(15) +{ + // NOTE: we don't know the local setting, but translation back and forth should work. + EXPECT_EQ (tl::to_string_from_local (tl::to_local ("Hällo\tWörld!").c_str ()), "Hällo\tWörld!"); + EXPECT_EQ (std::string ("Ä").size (), size_t (2)); + EXPECT_EQ (tl::to_string (std::wstring (L"Ä")), "Ä"); + EXPECT_EQ (tl::to_wstring (std::string ("Ä")).size (), 1); + EXPECT_EQ (tl::to_string (tl::to_wstring ("Utf8 supports emoticons: \xF0\x9F\x98\x81\nand Umlauts: äüö")).c_str (), "Utf8 supports emoticons: \xF0\x9F\x98\x81\nand Umlauts: äüö"); + + EXPECT_EQ (tl::to_upper_case ("äÄüÜöÖß"), "ÄÄÜÜÖÖß"); + EXPECT_EQ (tl::to_lower_case ("äÄüÜöÖß"), "ääüüööß"); +}