if (count == limit - 1) { value = string.substring(head); head = string.length(); } else { value = string.substring(head, matcher.start());
if (head != matcher.start() || isAllowEmpty) {  if (count == limit - 1) {  value = string.substring(head); head = string.length(); } else { value = string.substring(head, matcher.start()); head = matcher.end(); }  if ((flags & PREG_SPLIT_OFFSET_CAPTURE) != 0) { ArrayValue part = new ArrayValueImpl(); part.put(value); part.put(LongValue.create(startPosition));  result.put(part); } else { result.put(value); }  count++; } else
  public static Value preg_split(Env env,                                 StringValue patternString,                                 StringValue string,                                 @Optional("-1") long limit,                                 @Optional int flags)  {    if (limit < 0)      limit = Long.MAX_VALUE;    Pattern pattern = compileRegexp(patternString);    ArrayValue result = new ArrayValueImpl();    int head = 0;    Matcher matcher = pattern.matcher(string);    long count = 0;        boolean isAllowEmpty = (flags & PREG_SPLIT_NO_EMPTY) == 0;    while ((matcher.find()) && (count < limit)) {      // If empty and we are to skip empty strings, then skip      if (! isAllowEmpty && head == matcher.start()) {	head = matcher.end();	continue;      }      StringValue value;      int startPosition = head;      // If at limit, then just output the rest of string      if (count == limit - 1) {        value = string.substring(head);        head = string.length();      } else {        value = string.substring(head, matcher.start());        head = matcher.end();      }      if ((flags & PREG_SPLIT_OFFSET_CAPTURE) != 0) {        ArrayValue part = new ArrayValueImpl();        part.put(value);        part.put(LongValue.create(startPosition));        result.put(part);      } else {        result.put(value);      }      count++;      if ((flags & PREG_SPLIT_DELIM_CAPTURE) != 0) {	for (int i = 1; i <= matcher.groupCount(); i++) {	  String group = matcher.group(i);	  Value groupValue;	  if (group != null)	    groupValue = new StringValueImpl(group);	  else	    groupValue = NullValue.NULL;          if ((flags & PREG_SPLIT_OFFSET_CAPTURE) != 0) {            ArrayValue part = new ArrayValueImpl();            part.put(groupValue);            part.put(LongValue.create(matcher.start()));            result.put(part);          } else {	    result.put(groupValue);          }        }      }    }    if (head == string.length() && ! isAllowEmpty) {    }    else if ((head <= string.length()) && (count != limit)) {      if ((flags & PREG_SPLIT_OFFSET_CAPTURE) != 0) {        ArrayValue part = new ArrayValueImpl();        part.put(string.substring(head));        part.put(LongValue.create(head));        result.put(part);      } else {        result.put(string.substring(head));      }    }    return result;  }