diff options
| author | 2018-08-13 23:47:11 +0200 | |
|---|---|---|
| committer | 2018-08-19 08:12:52 -0400 | |
| commit | abc7a305d16d5ff939959164cff856af8f6d6ca1 (patch) | |
| tree | 25f392dea2124a133e7f27f2f43612ba0b6337bd /src/modules | |
| parent | AppVeyor: Grab openssl from vcpkg and fix vcpkg remove option (diff) | |
| download | KVIrc-abc7a305d16d5ff939959164cff856af8f6d6ca1.tar.gz KVIrc-abc7a305d16d5ff939959164cff856af8f6d6ca1.tar.bz2 KVIrc-abc7a305d16d5ff939959164cff856af8f6d6ca1.zip | |
List object updates; fix #2384
* fix a crash in $eof();
* add a boolean "reverse" parameter to $sort
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/objects/KvsObject_list.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/modules/objects/KvsObject_list.cpp b/src/modules/objects/KvsObject_list.cpp index 25ccf5dfc..d1fa8211d 100644 --- a/src/modules/objects/KvsObject_list.cpp +++ b/src/modules/objects/KvsObject_list.cpp @@ -48,6 +48,23 @@ [classfnc:list]$moveNext[/classfnc](),[classfnc:list]$movePrev[/classfnc](), [classfnc:list]$current[/classfnc]() and [classfnc:list]$eof[/classfnc]() functions. @functions: + !fn: $sort(<bReverse:bool>) + Sorts items in the list alphabetically ($true) or in reverse order ($false); Default to $false. + [example] + %list=$new(list);[br] + %list->$append('Foo');[br] + %list->$append('Bar');[br] + %list->$append('Dummy');[br] + %list->$append('Aria');[br] + [br] + %list->$sort(true);[br] + %list->$moveFirst();[br] + while(%list->$eof())[br] + {[br] + echo %list->$current();[br] + %list->$moveNext();[br] + }[br] + [/example] !fn: <integer> $count() Returns the number of items in the list !fn: <boolean> $isEmpty() @@ -168,7 +185,7 @@ KVSO_CLASS_FUNCTION(list, current) KVSO_CLASS_FUNCTION(list, eof) { CHECK_INTERNAL_POINTER(m_pDataList) - c->returnValue()->setBoolean(m_pDataList->current() != nullptr); + c->returnValue()->setBoolean(m_pDataList->safeCurrent() != nullptr); return true; } @@ -307,7 +324,13 @@ inline int kvi_compare(const KviKvsVariant * p1, const KviKvsVariant * p2) KVSO_CLASS_FUNCTION(list, sort) { CHECK_INTERNAL_POINTER(m_pDataList) + bool bReverse; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bReverse", KVS_PT_BOOL, KVS_PF_OPTIONAL, bReverse) + KVSO_PARAMETERS_END(c) m_pDataList->sort(); + if(bReverse) + m_pDataList->invert(); return true; } |
