Android String Search nestedIndexOf(final String s, final int startPos, final String open, final String close)

Here you can find the source of nestedIndexOf(final String s, final int startPos, final String open, final String close)

Description

nested Index Of

License

Open Source License

Declaration

public static int nestedIndexOf(final String s, final int startPos,
            final String open, final String close) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    public static int nestedIndexOf(final String s, final int startPos,
            final String open, final String close) {
        int depth = 0;
        for (int i = startPos; i < s.length();) {
            if (s.startsWith(close, i)) {
                if (depth == 0) {
                    return i;
                } else {
                    --depth;//from  w  ww  .j  ava 2  s .c  o m
                    i += close.length();
                }
            } else if (s.startsWith(open, i)) {
                ++depth;
                i += open.length();
            } else {
                ++i;
            }
        }
        return -1;
    }
}

Related

  1. safeIndexOf(String s, String search)
  2. indexOf(String str, String searchStr)
  3. skipSpaces(String s, int start)
  4. findFirstNotOf(String str, String chars)
  5. findFirstOf(String str, String chars)
  6. findLastNotOf(String str, String chars)
  7. findLastOf(String str, String chars)