private int findNamespaceStart(String text, int start, int stop) {

		if (!text.contains(Namespace.DELIMITER)) {
			return -1;
		}

		int colonCount = 0;
		int parenDepth = 0;
		int templateDepth = 0;
		int braceDepth = 0;
		boolean isNested = false;

		for (int i = start; i >= stop; i--) {

			char c = text.charAt(i);
			switch (c) {
				case ':': {
					colonCount++;
					if (colonCount == 2) {
						if (!isNested) {
							return i + 2;
						}
						colonCount = 0;
					}
					break;
				}
				case ' ': {
					if (!isNested) {
						return -1; // a space implies a return type when not nested
					}
					break;
				}
				case '(': {
					isNested = --parenDepth > 0 || templateDepth > 0 || braceDepth > 0;
					break;
				}
				case ')': {
					isNested = ++parenDepth > 0 || templateDepth > 0 || braceDepth > 0;
					break;
				}
				case '<': {
					isNested = parenDepth > 0 || --templateDepth > 0 || braceDepth > 0;
					break;
				}
				case '>': {
					isNested = parenDepth > 0 || ++templateDepth > 0 || braceDepth > 0;
					break;
				}
				case '{': {
					isNested = parenDepth > 0 || templateDepth > 0 || --braceDepth > 0;
					break;
				}
				case '}': {
					isNested = parenDepth > 0 || templateDepth > 0 || ++braceDepth > 0;
					break;
				}

				default:
					continue;
			}
		}

		return -1;
	}
Walks backward from the given start position to find the next namespace separator.  This
allows clients to determine if a given position is inside of a namespace.

@param text the text to search
@param start the start position
@param stop the stop position
@return the start index of the namespace entry containing the current {@code start}
        index; -1 if no namespace start is found
Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java