Skip to content

Commit ef2ca55

Browse files
committed
Add string_contains, to be clearer in code
1 parent ceede3e commit ef2ca55

File tree

2 files changed

+90
-22
lines changed

2 files changed

+90
-22
lines changed

.gitignore

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
/target/
2-
/.settings/
3-
/.idea/
4-
/plugins/
5-
/com/
6-
/CommandHelper/
7-
/bin/
8-
.classpath
9-
.project
10-
*.iml
11-
nbproject/
12-
nbactions-provisional-build.xml
13-
nbactions-release-profile.xml
14-
nbactions.xml
15-
nb-configuration.xml
16-
true
17-
/logs/
18-
/.logs/
19-
/preferences.*
20-
.DS_Store
21-
/test-backend/
22-
/nbproject/
1+
/target/
2+
/.settings/
3+
/.idea/
4+
/plugins/
5+
/com/
6+
/CommandHelper/
7+
/bin/
8+
.classpath
9+
.project
10+
*.iml
11+
nbproject/
12+
nbactions-provisional-build.xml
13+
nbactions-release-profile.xml
14+
nbactions.xml
15+
nb-configuration.xml
16+
true
17+
/logs/
18+
/.logs/
19+
/preferences.*
20+
.DS_Store
21+
/test-backend/
22+
/nbproject/
2323
/dependency-reduced-pom.xml

src/main/java/com/laytonsmith/core/functions/StringHandling.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ public ExampleScript[] examples() throws ConfigCompileException {
10621062
}
10631063

10641064
@api
1065+
@seealso({string_contains.class})
10651066
public static class string_position extends AbstractFunction implements Optimizable {
10661067

10671068
@Override
@@ -1124,6 +1125,73 @@ public Set<OptimizationOption> optimizationOptions() {
11241125
}
11251126
}
11261127

1128+
@api
1129+
@seealso({string_position.class})
1130+
public static class string_contains extends AbstractFunction implements Optimizable {
1131+
1132+
@Override
1133+
public Class<? extends CREThrowable>[] thrown() {
1134+
return new Class[]{CRENullPointerException.class};
1135+
}
1136+
1137+
@Override
1138+
public boolean isRestricted() {
1139+
return false;
1140+
}
1141+
1142+
@Override
1143+
public Boolean runAsync() {
1144+
return null;
1145+
}
1146+
1147+
@Override
1148+
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
1149+
String haystack = args[0].nval();
1150+
String needle = args[1].nval();
1151+
Static.AssertNonCNull(t, args);
1152+
return CBoolean.get(haystack.contains(needle));
1153+
}
1154+
1155+
@Override
1156+
public String getName() {
1157+
return "string_contains";
1158+
}
1159+
1160+
@Override
1161+
public Integer[] numArgs() {
1162+
return new Integer[]{2};
1163+
}
1164+
1165+
@Override
1166+
public String docs() {
1167+
return "boolean {haystack, needle} Returns true if the string needle is found anywhere within the string haystack."
1168+
+ " This is functionally equivalent to string_postion(@haystack, @needle) != -1, but is generally clearer.";
1169+
}
1170+
1171+
@Override
1172+
public Version since() {
1173+
return CHVersion.V3_3_2;
1174+
}
1175+
1176+
@Override
1177+
public Set<OptimizationOption> optimizationOptions() {
1178+
return EnumSet.of(OptimizationOption.CONSTANT_OFFLINE,
1179+
OptimizationOption.CACHE_RETURN,
1180+
OptimizationOption.NO_SIDE_EFFECTS);
1181+
}
1182+
1183+
@Override
1184+
public ExampleScript[] examples() throws ConfigCompileException {
1185+
return new ExampleScript[]{
1186+
new ExampleScript("Basic usage", "string_contains('haystack', 'hay');"),
1187+
new ExampleScript("Not found", "string_contains('abcd', 'wxyz');")
1188+
};
1189+
}
1190+
1191+
1192+
1193+
}
1194+
11271195
@api
11281196
@seealso({ArrayHandling.array_implode.class})
11291197
public static class split extends AbstractFunction implements Optimizable {

0 commit comments

Comments
 (0)