Accepts negative indices. Throws an error if path has no segments. Throws an error if index is out of range.
482818
function(index) {

            var segments = this.segments;
            var numSegments = segments.length;
            if (numSegments === 0) throw new Error('Path has no segments.');

            if (index < 0) index = numSegments + index; // convert negative indices to positive
            if (index >= numSegments || index < 0) throw new Error('Index out of range.');

            return segments[index];
        }
1178264
private static String badIndexMsg(int index, int size, String desc, Object... params) {
		if (index < 0) {
			return StrUtil.format("{} ({}) must not be negative", StrUtil.format(desc, params), index);
		} else if (size < 0) {
			throw new IllegalArgumentException("negative size: " + size);
		} else { // index >= size
			return StrUtil.format("{} ({}) must be less than size ({})", StrUtil.format(desc, params), index, size);
		}
	}
1330262
static int findNotZero( byte[] data , int index , int end ) {
		while( index < end && data[index] == 0 ) {
			index++;
		}
		return index;
	}
5036
private static function parseSegmentFromPath($path, &$index)
    {
        if ($index >= strlen($path)) {
            // A trailing '/' has caused the index to exceed the bounds
            // of the string - provide a helpful error message.
            throw self::parseError($path, strlen($path) - 1, "invalid trailing '/'");
        }
        if ($path[$index] === '{') {
            // Validate that the { has a matching }
            $closingBraceIndex = strpos($path, '}', $index);
            if ($closingBraceIndex === false) {
                throw self::parseError(
                    $path,
                    strlen($path),
                    "Expected '}' to match '{' at index $index, got end of string"
                );
            }

            $segmentStringLengthWithoutBraces = $closingBraceIndex - $index - 1;
            $segmentStringWithoutBraces = substr($path, $index + 1, $segmentStringLengthWithoutBraces);
            $index = $closingBraceIndex + 1;
            return self::parseVariableSegment($segmentStringWithoutBraces);
        } else {
            $nextSlash = strpos($path, '/', $index);
            if ($nextSlash === false) {
                $nextSlash = strlen($path);
            }
            $segmentString = substr($path, $index, $nextSlash - $index);
            $index = $nextSlash;
            return self::parse($segmentString, $path, $index);
        }
    }
1251741
def check_path(path):
    
    if path is None or path == b'' or path.startswith(b'/'):
        raise ValueError("illegal path '%s'" % path)

    if (
        (sys.version_info[0] >= 3 and not isinstance(path, bytes)) and
        (sys.version_info[0] == 2 and not isinstance(path, str))
    ):
        raise TypeError("illegale type for path '%r'" % path)

    return path
290046
function chainStepsNoError() {
	var steps = slice.call(arguments).map(function(step) {
		return notHandlingError(step);
	});
	return chainSteps.apply(null, steps);
}
252262
def _indices(self):
        """"""
        path = self.parent
        layer = path.parent
        for path_index in range(len(layer.paths)):
            if path == layer.paths[path_index]:
                for node_index in range(len(path.nodes)):
                    if self == path.nodes[node_index]:
                        return Point(path_index, node_index)
        return None
72943
private void ensureCapacity(final int index, final int length)
    {
        if (index < 0)
        {
            throw new IndexOutOfBoundsException("index cannot be negative: index=" + index);
        }

        final long resultingPosition = index + (long)length;
        final int currentArrayLength = byteArray.length;
        if (resultingPosition > currentArrayLength)
        {
            if (currentArrayLength >= MAX_ARRAY_LENGTH)
            {
                throw new IndexOutOfBoundsException(
                    "index=" + index + " length=" + length + " maxCapacity=" + MAX_ARRAY_LENGTH);
            }

            byteArray = Arrays.copyOf(byteArray, calculateExpansion(currentArrayLength, (int)resultingPosition));
        }
    }
1177085
function isValidPath(path, allowDots)
	{
		if (typeof path !== 'string')
			return false;
		if (!path)
			return false;
		if (!/^([a-z]:[\/\\])?[a-z0-9_~\/\.\-]+$/i.test(path))
			return false;
		if (!allowDots && /^\.{1,2}$/.test(path))
			return false;

		return true;
	}
746973
def normalizeIndex(value):
    
    if value is not None:
        if not isinstance(value, int):
            raise TypeError("Indexes must be None or integers, not %s."
                            % type(value).__name__)
    return value
909680
private void negateRange(final ShortBuffer buffer, final int startIndex, final int lastIndex,
      final int startRange, final int lastRange) {
    // compute the negation into buffer

    int outPos = 0;
    int inPos = startIndex; // value here always >= valInRange,
    // until it is exhausted
    // n.b., we can start initially exhausted.

    int valInRange = startRange;
    for (; valInRange < lastRange && inPos <= lastIndex; ++valInRange) {
      if ((short) valInRange != content.get(inPos)) {
        buffer.put(outPos++, (short) valInRange);
      } else {
        ++inPos;
      }
    }

    // if there are extra items (greater than the biggest
    // pre-existing one in range), buffer them
    for (; valInRange < lastRange; ++valInRange) {
      buffer.put(outPos++, (short) valInRange);
    }

    if (outPos != buffer.limit()) {
      throw new RuntimeException(
          "negateRange: outPos " + outPos + " whereas buffer.length=" + buffer.limit());
    }
    assert outPos == buffer.limit();
    // copy back from buffer...caller must ensure there is room
    int i = startIndex;
    int len = buffer.limit();
    for (int k = 0; k < len; ++k) {
      final short item = buffer.get(k);
      content.put(i++, item);
    }
  }
618618
protected void ensureRestrictedIndex(final int index) {
        if (index < 0) throw new IndexOutOfBoundsException("Index (" + index + ") is negative");
        if (index >= size())
            throw new IndexOutOfBoundsException("Index (" + index + ") is greater than or equal to list size (" + (size()) + ")");
    }
665384
def validate(path, regex=None):
    
    validated = []
    for elem in path:
        key = elem[0]
        strkey = str(key)
        if (regex and (not regex.findall(strkey))):
            raise dpath.exceptions.InvalidKeyName("{} at {} does not match the expression {}"
                                                  "".format(strkey,
                                                            validated,
                                                            regex.pattern))
        validated.append(strkey)
1057102
def is_negative(pattern, flags):
    """"""

    if flags & MINUSNEGATE:
        return flags & NEGATE and pattern[0:1] in MINUS_NEGATIVE_SYM
    else:
        return flags & NEGATE and pattern[0:1] in NEGATIVE_SYM
1296715
def negative_directional_index(close_data, high_data, low_data, period):
    
    catch_errors.check_for_input_len_diff(close_data, high_data, low_data)
    ndi = (100 *
           smma(negative_directional_movement(high_data, low_data), period) /
           atr(close_data, period)
           )
    return ndi
237752
private void negateRange(final short[] buffer, final int startIndex, final int lastIndex,
      final int startRange, final int lastRange) {
    // compute the negation into buffer

    int outPos = 0;
    int inPos = startIndex; // value here always >= valInRange,
    // until it is exhausted
    // n.b., we can start initially exhausted.

    int valInRange = startRange;
    for (; valInRange < lastRange && inPos <= lastIndex; ++valInRange) {
      if ((short) valInRange != content[inPos]) {
        buffer[outPos++] = (short) valInRange;
      } else {
        ++inPos;
      }
    }

    // if there are extra items (greater than the biggest
    // pre-existing one in range), buffer them
    for (; valInRange < lastRange; ++valInRange) {
      buffer[outPos++] = (short) valInRange;
    }

    if (outPos != buffer.length) {
      throw new RuntimeException(
          "negateRange: outPos " + outPos + " whereas buffer.length=" + buffer.length);
    }
    // copy back from buffer...caller must ensure there is room
    int i = startIndex;
    for (short item : buffer) {
      content[i++] = item;
    }
  }
1013139
private void eatSplicedRange(List segments) {
        Token token = tokenizer.peekToken(0);
        if (token == null) {// ∈
            return;
        }
        switch (token.getKind()) {
            case LITERAL_STRING:
                segments.add(token.getData());
                break;
            case LSQUARE:
                tokenizer.nextToken();
                List<?> list = new ArrayList<>();
                eatRange(list);
                if (list.isEmpty()) {
                    empty = true;
                } else {
                    segments.add(list);
                }
                tokenizer.peekToken(0, TokenKind.RSQUARE);
                break;
            default:
                return;
        }
        if (tokenizer.hasMoreTokens()) {// ∈
            tokenizer.nextToken();
            eatSplicedRange(segments);
        }
    }