diff options
author | Yvan Lussaud | 2015-02-20 14:02:44 +0000 |
---|---|---|
committer | Laurent Goubet | 2015-03-13 13:02:43 +0000 |
commit | d0c273dd29bc1de973bc1f8ec67007209b87baf7 (patch) | |
tree | dc9893d64f8d5a1dd7a15e960b164bfba6fc7905 | |
parent | d6902493e87b4da677634565beaec149941a4261 (diff) | |
download | org.eclipse.acceleo-d0c273dd29bc1de973bc1f8ec67007209b87baf7.tar.gz org.eclipse.acceleo-d0c273dd29bc1de973bc1f8ec67007209b87baf7.tar.xz org.eclipse.acceleo-d0c273dd29bc1de973bc1f8ec67007209b87baf7.zip |
Added strstr() service.
Change-Id: I1f096df17e5221f3ba2ff796ae437d146b49de16
2 files changed, 35 insertions, 0 deletions
diff --git a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/services/StringServices.java b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/services/StringServices.java index f3c725377..98183c883 100644 --- a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/services/StringServices.java +++ b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/services/StringServices.java @@ -484,4 +484,17 @@ public class StringServices { return Integer.valueOf(self.compareTo(s1)); } + /** + * Searches r in self. + * + * @param self + * the current {@link String} + * @param r + * the {@link String} to search + * @return <code>true</code> if r is found, <code>false</code> otherwise + */ + public Boolean strstr(String self, String r) { + return Boolean.valueOf(self.indexOf(r) > -1); + } + } diff --git a/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/services/tests/StringServicesTest.java b/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/services/tests/StringServicesTest.java index 33dcc80c6..98e0bffda 100644 --- a/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/services/tests/StringServicesTest.java +++ b/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/services/tests/StringServicesTest.java @@ -864,4 +864,26 @@ public class StringServicesTest extends AbstractServicesTest { assertEquals(Integer.valueOf(0), stringServices.strcmp("strcmp operation", "strcmp operation")); assertEquals(Integer.valueOf(-17), stringServices.strcmp("strcmp operation", "strtok")); } + + @Test(expected = java.lang.NullPointerException.class) + public void strstrNullNull() { + stringServices.strstr(null, null); + } + + @Test(expected = java.lang.NullPointerException.class) + public void strstrStringNull() { + stringServices.strstr("", null); + } + + @Test(expected = java.lang.NullPointerException.class) + public void strstrNullString() { + stringServices.strstr(null, ""); + } + + @Test + public void strstr() { + assertEquals(Boolean.TRUE, stringServices.strstr("strstr operation", "ope")); + assertEquals(Boolean.FALSE, stringServices.strstr("strstr operation", "false")); + } + } |