• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision353 (tree)
Zeit2020-10-22 23:15:22
Autorquiret

Log Message

- added eir::MultiString bindings for eir::String/eir::FixedString
- added support for eir::FixedString in string comparison functions

Ändern Zusammenfassung

Diff

--- common/sdk/MultiString.h (revision 352)
+++ common/sdk/MultiString.h (revision 353)
@@ -35,6 +35,7 @@
3535 #include "rwlist.hpp"
3636
3737 #include "String.h"
38+#include "FixedString.h"
3839
3940 namespace eir
4041 {
@@ -998,7 +999,7 @@
998999 }
9991000
10001001 template <typename charType, typename... stringArgs>
1001- inline explicit MultiString( const eir::String <charType, stringArgs...>& right )
1002+ inline MultiString( const eir::String <charType, stringArgs...>& right )
10021003 {
10031004 this->data.strData = CreateStringProvider <charType> ();
10041005
@@ -1005,6 +1006,14 @@
10051006 this->data.strData->AppendChars( right.GetConstString(), right.GetLength() );
10061007 }
10071008
1009+ template <typename charType>
1010+ inline MultiString( const eir::FixedString <charType>& right )
1011+ {
1012+ this->data.strData = CreateStringProvider <charType> ();
1013+
1014+ this->data.strData->AppendChars( right.GetConstString(), right.GetLength() );
1015+ }
1016+
10081017 // Special constructor for creating a string with allocator arguments.
10091018 template <typename... Args>
10101019 inline MultiString( constr_with_alloc _, Args&&... allocArgs )
@@ -1214,7 +1223,21 @@
12141223
12151224 this->data.strData->InsertChars( offset, src, srcCPCount );
12161225 }
1226+ template <typename otherCharType>
1227+ inline void insert( size_t offset, const eir::FixedString <otherCharType>& srcStr )
1228+ {
1229+ this->compat_upgrade <otherCharType> ();
12171230
1231+ this->data.strData->InsertChars( offset, srcStr.GetConstString(), srcStr.GetLength() );
1232+ }
1233+ template <typename otherCharType, typename... otherStringArgs>
1234+ inline void insert( size_t offset, const eir::String <otherCharType, otherStringArgs...>& srcStr )
1235+ {
1236+ this->compat_upgrade <otherCharType> ();
1237+
1238+ this->data.strData->InsertChars( offset, srcStr.GetConstString(), srcStr.GetLength() );
1239+ }
1240+
12181241 // Inserts a string into a character offset.
12191242 template <typename otherCharType>
12201243 inline void insert( size_t offset, const otherCharType *src )
@@ -1256,7 +1279,21 @@
12561279
12571280 this->data.strData->AppendChars( appendStr, appendCPLen );
12581281 }
1282+ template <typename charType>
1283+ inline void append( const eir::FixedString <charType>& appendStr )
1284+ {
1285+ this->compat_upgrade <charType> ();
12591286
1287+ this->data.strData->AppendChars( appendStr.GetConstString(), appendStr.GetLength() );
1288+ }
1289+ template <typename charType, typename... otherStringArgs>
1290+ inline void append( const eir::String <charType, otherStringArgs...>& appendStr )
1291+ {
1292+ this->compat_upgrade <charType> ();
1293+
1294+ this->data.strData->AppendChars( appendStr.GetConstString(), appendStr.GetLength() );
1295+ }
1296+
12601297 template <typename charType>
12611298 inline void append( const charType *appendStr )
12621299 {
@@ -1314,6 +1351,35 @@
13141351 return *this;
13151352 }
13161353
1354+ template <typename otherCharType>
1355+ inline MultiString& operator = ( const eir::FixedString <otherCharType>& right )
1356+ {
1357+ if ( this->data.strData )
1358+ {
1359+ DestroyStringProvider( this->data.strData );
1360+
1361+ this->data.strData = nullptr;
1362+ }
1363+
1364+ this->operator += ( right );
1365+
1366+ return *this;
1367+ }
1368+ template <typename otherCharType, typename... otherStringArgs>
1369+ inline MultiString& operator = ( const eir::String <otherCharType, otherStringArgs...>& right )
1370+ {
1371+ if ( this->data.strData )
1372+ {
1373+ DestroyStringProvider( this->data.strData );
1374+
1375+ this->data.strData = nullptr;
1376+ }
1377+
1378+ this->operator += ( right );
1379+
1380+ return *this;
1381+ }
1382+
13171383 // NOTE: this copy operator uses the fact that both MultiString have the same allocatorType.
13181384 inline MultiString& operator = ( const MultiString& right )
13191385 {
@@ -1364,7 +1430,44 @@
13641430
13651431 return isEqual;
13661432 }
1433+
1434+ template <typename charType>
1435+ inline bool equals( const eir::FixedString <charType>& rightStr, bool caseSensitive = true ) const
1436+ {
1437+ bool isEqual = false;
13671438
1439+ size_t rightLen = rightStr.GetLength();
1440+
1441+ if ( this->data.strData )
1442+ {
1443+ isEqual = ( this->data.strData->CompareToChars( rightStr.GetConstString(), rightLen, caseSensitive ) == eCompResult::EQUAL );
1444+ }
1445+ else if ( rightLen == 0 )
1446+ {
1447+ isEqual = true;
1448+ }
1449+
1450+ return isEqual;
1451+ }
1452+ template <typename charType, typename... otherStringArgs>
1453+ inline bool equals( const eir::String <charType, otherStringArgs...>& rightStr, bool caseSensitive = true ) const
1454+ {
1455+ bool isEqual = false;
1456+
1457+ size_t rightLen = rightStr.GetLength();
1458+
1459+ if ( this->data.strData )
1460+ {
1461+ isEqual = ( this->data.strData->CompareToChars( rightStr.GetConstString(), rightLen, caseSensitive ) == eCompResult::EQUAL );
1462+ }
1463+ else if ( rightLen == 0 )
1464+ {
1465+ isEqual = true;
1466+ }
1467+
1468+ return isEqual;
1469+ }
1470+
13681471 inline bool equals( const MultiString& right, bool caseSensitive = true ) const
13691472 {
13701473 bool isEqual = false;
@@ -1385,7 +1488,6 @@
13851488 {
13861489 return equals( right, true );
13871490 }
1388-
13891491 template <typename... otherStringArgs>
13901492 inline bool operator == ( const MultiString <otherStringArgs...>& right ) const
13911493 {
@@ -1404,7 +1506,6 @@
14041506 {
14051507 return !( this->operator == ( right ) );
14061508 }
1407-
14081509 template <typename... otherStringArgs>
14091510 inline bool operator != ( const MultiString <otherStringArgs...>& right ) const
14101511 {
@@ -1412,16 +1513,66 @@
14121513 }
14131514
14141515 template <typename otherCharType>
1415- inline bool operator == ( const otherCharType *right ) const
1516+ friend inline bool operator == ( const MultiString& left, const otherCharType *right )
14161517 {
1417- return equals( right, true );
1518+ return left.equals( right, true );
14181519 }
1520+ template <typename otherCharType>
1521+ friend inline bool operator == ( const otherCharType *left, const MultiString& right )
1522+ {
1523+ return right.equals( left, true );
1524+ }
1525+ template <typename otherCharType>
1526+ friend inline bool operator == ( const MultiString& left, const eir::FixedString <otherCharType>& right )
1527+ {
1528+ return left.equals( right, true );
1529+ }
1530+ template <typename otherCharType>
1531+ friend inline bool operator == ( const eir::FixedString <otherCharType>& left, const MultiString& right )
1532+ {
1533+ return right.equals( left, true );
1534+ }
1535+ template <typename otherCharType, typename... otherStringArgs>
1536+ friend inline bool operator == ( const MultiString& left, const eir::String <otherCharType, otherStringArgs...>& right )
1537+ {
1538+ return left.equals( right, true );
1539+ }
1540+ template <typename otherCharType, typename... otherStringArgs>
1541+ friend inline bool operator == ( const eir::String <otherCharType, otherStringArgs...>& left, const MultiString& right )
1542+ {
1543+ return right.equals( left, true );
1544+ }
14191545
14201546 template <typename otherCharType>
1421- inline bool operator != ( const otherCharType *right ) const
1547+ friend inline bool operator != ( const MultiString& left, const otherCharType *right )
14221548 {
1423- return !( this->operator == ( right ) );
1549+ return !( left == right );
14241550 }
1551+ template <typename otherCharType>
1552+ friend inline bool operator != ( const otherCharType *left, const MultiString& right )
1553+ {
1554+ return !( left == right );
1555+ }
1556+ template <typename otherCharType>
1557+ friend inline bool operator != ( const MultiString& left, const eir::FixedString <otherCharType>& right )
1558+ {
1559+ return !( left == right );
1560+ }
1561+ template <typename otherCharType>
1562+ friend inline bool operator != ( const eir::FixedString <otherCharType>& left, const MultiString& right )
1563+ {
1564+ return !( left == right );
1565+ }
1566+ template <typename otherCharType, typename... otherStringArgs>
1567+ friend inline bool operator != ( const MultiString& left, const eir::String <otherCharType, otherStringArgs...>& right )
1568+ {
1569+ return !( left == right );
1570+ }
1571+ template <typename otherCharType, typename... otherStringArgs>
1572+ friend inline bool operator != ( const eir::String <otherCharType, otherStringArgs...>& left, const MultiString& right )
1573+ {
1574+ return !( left == right );
1575+ }
14251576
14261577 inline MultiString operator + ( const MultiString& right ) const
14271578 {
@@ -1469,19 +1620,45 @@
14691620 right.insert( 0, left );
14701621 return std::move( right );
14711622 }
1623+ template <typename charType>
1624+ AINLINE friend MultiString operator + ( MultiString&& left, const eir::FixedString <charType>& right )
1625+ {
1626+ left.compat_upgrade <charType> ();
1627+ left.append( right );
1628+ return std::move( left );
1629+ }
1630+ template <typename charType>
1631+ AINLINE friend MultiString operator + ( const eir::FixedString <charType>& left, MultiString&& right )
1632+ {
1633+ right.compat_upgrade <charType> ();
1634+ right.insert( 0, left );
1635+ return std::move( right );
1636+ }
1637+ template <typename charType, typename... otherStringArgs>
1638+ AINLINE friend MultiString operator + ( MultiString&& left, const eir::String <charType, otherStringArgs...>& right )
1639+ {
1640+ left.compat_upgrade <charType> ();
1641+ left.append( right );
1642+ return std::move( left );
1643+ }
1644+ template <typename charType, typename... otherStringArgs>
1645+ AINLINE friend MultiString operator + ( const eir::String <charType, otherStringArgs...>& left, MultiString&& right )
1646+ {
1647+ right.compat_upgrade <charType> ();
1648+ right.insert( 0, left );
1649+ return std::move( right );
1650+ }
14721651
14731652 template <typename... otherStringArgs>
1474- inline MultiString operator + ( const MultiString <otherStringArgs...>& right ) const
1653+ AINLINE friend MultiString operator + ( MultiString&& left, const MultiString <otherStringArgs...>& right )
14751654 {
1476- MultiString newPath( *this );
1477-
14781655 right.char_dispatch(
14791656 [&]( const auto *str )
14801657 {
1481- newPath.append( str, right.size() );
1658+ left.append( str, right.size() );
14821659 });
14831660
1484- return newPath;
1661+ return std::move( left );
14851662 }
14861663
14871664 inline MultiString& operator += ( const MultiString& right )
@@ -1510,6 +1687,15 @@
15101687 return *this;
15111688 }
15121689
1690+ template <typename otherCharType>
1691+ inline MultiString& operator += ( const eir::FixedString <otherCharType>& right )
1692+ {
1693+ this->compat_upgrade <otherCharType> ();
1694+
1695+ this->data.strData->AppendChars( right.GetConstString(), right.GetLength() );
1696+
1697+ return *this;
1698+ }
15131699 template <typename otherCharType, typename... otherStringArgs>
15141700 inline MultiString& operator += ( const eir::String <otherCharType, otherStringArgs...>& right )
15151701 {
--- common/sdk/UniChar.strmodel.h (revision 352)
+++ common/sdk/UniChar.strmodel.h (revision 353)
@@ -13,6 +13,8 @@
1313 #ifndef _EIRREPO_CHARACTER_CHAIN_FUNCTIONS_
1414 #define _EIRREPO_CHARACTER_CHAIN_FUNCTIONS_
1515
16+#include <sdk/FixedString.h>
17+
1618 #include "MacroUtils.h"
1719
1820 //TODO: find ways to share as much code as possible between the different string model functions!
@@ -150,6 +152,19 @@
150152 return ( StringComparatorGeneric( srcStr, dstStr, caseSensitive, srcProc, dstProc ) == eir::eCompResult::EQUAL );
151153 }
152154
155+template <typename srcCharType, typename dstCharType>
156+inline bool UniversalCompareStrings(
157+ const eir::FixedString <srcCharType>& srcStr,
158+ const eir::FixedString <dstCharType>& dstStr,
159+ bool caseSensitive
160+)
161+{
162+ boundedCharItemProc <srcCharType> srcProc( srcStr.GetLength() );
163+ boundedCharItemProc <dstCharType> dstProc( dstStr.GetLength() );
164+
165+ return ( StringComparatorGeneric( srcStr.GetConstString(), dstStr.GetConstString(), caseSensitive, srcProc, dstProc ) == eir::eCompResult::EQUAL );
166+}
167+
153168 template <typename srcCharType, typename dstCharType, typename... srcStringArgs, typename... dstStringArgs>
154169 inline bool UniversalCompareStrings(
155170 const eir::String <srcCharType, srcStringArgs...>& src,
@@ -177,6 +192,19 @@
177192 }
178193
179194 template <typename srcCharType, typename dstCharType>
195+inline bool BoundedStringEqual(
196+ const eir::FixedString <srcCharType>& srcStr,
197+ const dstCharType *dstStr,
198+ bool caseSensitive
199+)
200+{
201+ boundedCharItemProc <srcCharType> srcProc( srcStr.GetLength() );
202+ unboundedCharItemProc <dstCharType> dstProc;
203+
204+ return ( StringComparatorGeneric( srcStr.GetConstString(), dstStr, caseSensitive, srcProc, dstProc ) == eir::eCompResult::EQUAL );
205+}
206+
207+template <typename srcCharType, typename dstCharType>
180208 inline bool StringEqualToZero(
181209 const srcCharType *srcStr,
182210 const dstCharType *dstStr,
@@ -203,6 +231,19 @@
203231 }
204232
205233 template <typename srcCharType, typename dstCharType>
234+inline eir::eCompResult FixedStringCompare(
235+ const eir::FixedString <srcCharType>& srcStr,
236+ const dstCharType *dstStr, size_t dstCPLen,
237+ bool caseSensitive
238+)
239+{
240+ boundedCharItemProc <srcCharType> srcProc( srcStr.GetLength() );
241+ boundedCharItemProc <dstCharType> dstProc( dstCPLen );
242+
243+ return StringComparatorGeneric( srcStr.GetConstString(), dstStr, caseSensitive, srcProc, dstProc );
244+}
245+
246+template <typename srcCharType, typename dstCharType>
206247 inline eir::eCompResult BoundedStringCompare(
207248 const srcCharType *srcStr, size_t srcCPLen,
208249 const dstCharType *dstStr,
@@ -216,6 +257,19 @@
216257 }
217258
218259 template <typename srcCharType, typename dstCharType>
260+inline eir::eCompResult BoundedStringCompare(
261+ const eir::FixedString <srcCharType>& srcStr,
262+ const dstCharType *dstStr,
263+ bool caseSensitive
264+)
265+{
266+ boundedCharItemProc <srcCharType> srcProc( srcStr.GetLength() );
267+ unboundedCharItemProc <dstCharType> dstProc;
268+
269+ return StringComparatorGeneric( srcStr.GetConstString(), dstStr, caseSensitive, srcProc, dstProc );
270+}
271+
272+template <typename srcCharType, typename dstCharType>
219273 inline eir::eCompResult StringCompareToZero(
220274 const srcCharType *srcStr,
221275 const dstCharType *dstStr,
Show on old repository browser