3 * Copyright 2007 Google Inc.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 * Various utilities for working with Strings.
21 namespace google\appengine\util
;
23 final class StringUtil
{
25 * Return true if the first paramater contains the second parameter at the
28 * @param string $input The input string which may contain the suffix.
29 * @param string $suffix The string to look for at the end of the input.
31 * @return boolean <code>true</code> iff the input contains the suffix at the
34 public static function endsWith($input, $suffix) {
35 return substr($input, -strlen($suffix)) === $suffix;
39 * @param string $input The string which may contain the prefix at the start.
40 * @param string $prefix The string to look for at the start of the input.
42 * @return boolean <code>true</code> iff the input contains the prefix at the
45 public static function startsWith($input, $prefix) {
46 return substr($input, 0, strlen($prefix)) === $prefix;
50 * @param string $input The string which may not be url safe.
52 * @return string A Base64 encoded url safe string.
54 public static function base64UrlEncode($input) {
55 return strtr(base64_encode($input), '+/=', '-_,');
59 * @param string $input The url safe Base64 encoded string.
61 * @return string The original string which may not be url safe.
63 public static function base64UrlDecode($input) {
64 return base64_decode(strtr($input, '-_,', '+/='));