You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LocatorUtil.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.componentlocator;
  17. /**
  18. * Common String manipulator utilities used in VaadinFinderLocatorStrategy and
  19. * SelectorPredicates.
  20. *
  21. * @since 7.2
  22. * @author Vaadin Ltd
  23. */
  24. public class LocatorUtil {
  25. /**
  26. * Find first occurrence of character that's not inside quotes starting from
  27. * specified index.
  28. *
  29. * @param str
  30. * Full string for searching
  31. * @param find
  32. * Character we want to find
  33. * @param startingAt
  34. * Index where we start
  35. * @return Index of character. -1 if character not found
  36. */
  37. protected static int indexOfIgnoringQuoted(String str, char find,
  38. int startingAt) {
  39. boolean quote = false;
  40. String quoteChars = "'\"";
  41. char currentQuote = '"';
  42. for (int i = startingAt; i < str.length(); ++i) {
  43. char cur = str.charAt(i);
  44. if (quote) {
  45. if (cur == currentQuote) {
  46. quote = !quote;
  47. }
  48. continue;
  49. } else if (cur == find) {
  50. return i;
  51. } else {
  52. if (quoteChars.indexOf(cur) >= 0) {
  53. currentQuote = cur;
  54. quote = !quote;
  55. }
  56. }
  57. }
  58. return -1;
  59. }
  60. /**
  61. * Find first occurrence of character that's not inside quotes starting from
  62. * the beginning of string.
  63. *
  64. * @param str
  65. * Full string for searching
  66. * @param find
  67. * Character we want to find
  68. * @return Index of character. -1 if character not found
  69. */
  70. protected static int indexOfIgnoringQuoted(String str, char find) {
  71. return indexOfIgnoringQuoted(str, find, 0);
  72. }
  73. }