| 138 | } |
| 139 | |
| 140 | @StarlarkMethod( |
| 141 | name = "join", |
| 142 | doc = |
| 143 | "Returns a string in which the string elements of the argument have been " |
| 144 | + "joined by this string as a separator. Example:<br>" |
| 145 | + "<pre class=\"language-python\">\"|\".join([\"a\", \"b\", \"c\"]) == \"a|b|c\"" |
| 146 | + "</pre>", |
| 147 | parameters = { |
| 148 | @Param(name = "self"), |
| 149 | @Param( |
| 150 | name = "elements", |
| 151 | allowedTypes = {@ParamType(type = StarlarkIterable.class, generic1 = String.class)}, |
| 152 | doc = "The objects to join.") |
| 153 | }, |
| 154 | useStarlarkThread = true) |
| 155 | public String join(String self, StarlarkIterable<?> elements, StarlarkThread thread) |
| 156 | throws EvalException { |
| 157 | Iterable<?> items = Starlark.toIterable(elements); |
| 158 | int i = 0; |
| 159 | for (Object item : items) { |
| 160 | if (!(item instanceof String)) { |
| 161 | throw Starlark.errorf( |
| 162 | "expected string for sequence element %d, got '%s' of type %s", |
| 163 | i, Starlark.str(item, thread.getSemantics()), Starlark.type(item)); |
| 164 | } |
| 165 | i++; |
| 166 | } |
| 167 | return Joiner.on(self).join(items); |
| 168 | } |
| 169 | |
| 170 | @StarlarkMethod( |
| 171 | name = "lower", |