Skip to content

Package: UrlEncoding

UrlEncoding

nameinstructionbranchcomplexitylinemethod
decodedUtf8(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
encodedUtf8(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.util;
27:
28: import javax.annotation.Nonnull;
29: import java.net.URLDecoder;
30: import java.net.URLEncoder;
31: import lombok.NoArgsConstructor;
32: import static java.nio.charset.StandardCharsets.UTF_8;
33: import static lombok.AccessLevel.PRIVATE;
34:
35: /***************************************************************************************************************************************************************
36: *
37: * A wrapper around {@link URLDecoder} and {@link URLEncoder} so functional descriptors can be used.
38: *
39: * @author Fabrizio Giudici
40: *
41: **************************************************************************************************************************************************************/
42: @NoArgsConstructor(access = PRIVATE)
43: public final class UrlEncoding
44: {
45: /***********************************************************************************************************************************************************
46: * Decodes a string in UTF-8.
47: *
48: * @param string the string
49: * @return the decoded string
50: **********************************************************************************************************************************************************/
51: @Nonnull @SuppressWarnings("squid:S00112")
52: public static String decodedUtf8 (@Nonnull final String string)
53: {
54: return URLDecoder.decode(string, UTF_8);
55: }
56:
57: /***********************************************************************************************************************************************************
58: * Encodes a string in UTF-8.
59: *
60: * @param string the string
61: * @return the encoded string
62: *
63: **********************************************************************************************************************************************************/
64: @Nonnull @SuppressWarnings("squid:S00112")
65: public static String encodedUtf8 (@Nonnull final String string)
66: {
67: return URLEncoder.encode(string, UTF_8);
68: }
69: }