MCPcopy Create free account
hub / github.com/ZDoom/Raze / GetInsertIndex

Function GetInsertIndex

source/common/menu/menudef.cpp:802–834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

800//=============================================================================
801
802static int GetInsertIndex(FScanner& sc, DMenuDescriptor* desc)
803{
804 bool before = sc.CheckString("BEFORE");
805 bool after = sc.CheckString("AFTER");
806
807 int insertIndex = -1;
808
809 if (before || after)
810 {
811 // Find an existing menu item to use as insertion point
812 sc.MustGetString();
813
814 int n = desc->mItems.Size();
815 for (int i = 0; i < n; i++)
816 {
817 auto item = desc->mItems[i];
818
819 if (item->mAction == sc.String)
820 {
821 insertIndex = before ? i : i + 1;
822 break;
823 }
824 }
825
826 // Inserting after the last item is the same as inserting at the end
827 if (insertIndex == n) insertIndex = -1;
828
829 // Don't error out if we haven't found a suitable item
830 // to avoid backwards compatibility issues.
831 }
832
833 return insertIndex;
834}
835
836//=============================================================================
837//

Callers 2

ParseAddListMenuFunction · 0.85
ParseAddOptionMenuFunction · 0.85

Calls 3

MustGetStringMethod · 0.80
CheckStringMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected