Debugger: Add dedicated functions for global {un}init.
[haiku.git] / src / apps / debugger / types / ArrayIndexPath.cpp
blobc91cdf408093c494f5c5c9a3c9f2d0edebba57c5
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "ArrayIndexPath.h"
9 #include <stdlib.h>
11 #include <String.h>
14 static const char kIndexSeparator = ';';
17 ArrayIndexPath::ArrayIndexPath()
22 ArrayIndexPath::ArrayIndexPath(const ArrayIndexPath& other)
24 fIndices(other.fIndices)
29 ArrayIndexPath::~ArrayIndexPath()
34 status_t
35 ArrayIndexPath::SetTo(const char* path)
37 fIndices.Clear();
39 if (path == NULL)
40 return B_OK;
42 while (*path != '\0') {
43 char* numberEnd;
44 int64 index = strtoll(path, &numberEnd, 0);
45 if (numberEnd == path)
46 return B_BAD_VALUE;
47 path = numberEnd;
49 if (!fIndices.Add(index))
50 return B_NO_MEMORY;
52 if (*path == '\0')
53 break;
55 if (*path != kIndexSeparator)
56 return B_BAD_VALUE;
57 path++;
60 return B_OK;
64 void
65 ArrayIndexPath::Clear()
67 fIndices.Clear();
71 bool
72 ArrayIndexPath::GetPathString(BString& path) const
74 path.Truncate(0);
76 int32 count = CountIndices();
77 for (int32 i = 0; i < count; i++) {
78 // append separator for all but the first index
79 if (i > 0) {
80 int32 oldLength = path.Length();
81 if (path.Append(kIndexSeparator, 1).Length() != oldLength + 1)
82 return false;
85 // append index
86 int32 oldLength = path.Length();
87 if ((path << IndexAt(i)).Length() == oldLength)
88 return false;
91 return true;
95 ArrayIndexPath&
96 ArrayIndexPath::operator=(const ArrayIndexPath& other)
98 fIndices = other.fIndices;
99 return *this;