aboutsummaryrefslogtreecommitdiff
path: root/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/ShortcodeUtils.java
blob: 09480f156364133884cd2f0d9d80474d15579227 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package org.wordpress.android.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ShortcodeUtils {
    public static String getVideoPressShortcodeFromId(String videoPressId) {
        if (videoPressId == null || videoPressId.isEmpty()) {
            return "";
        }

        return "[wpvideo " + videoPressId + "]";
    }

    public static String getVideoPressIdFromShortCode(String shortcode) {
        String videoPressId = "";

        if (shortcode != null) {
            String videoPressShortcodeRegex = "^\\[wpvideo (.*)]$";

            Pattern pattern = Pattern.compile(videoPressShortcodeRegex);
            Matcher matcher = pattern.matcher(shortcode);

            if (matcher.find()) {
                videoPressId = matcher.group(1);
            }
        }

        return videoPressId;
    }
}