import 'package:flutter/material.dart';

class StringUtils {
  StringUtils._init();
  static StringUtils? _instance;
  static StringUtils get instance => _instance ??= StringUtils._init();

  List<InlineSpan> parseAddressFromMapAPI(String addressString) {
    RegExp regex = RegExp(r'<span class="([^"]+)">([^<]+)</span>');
    List<InlineSpan> textSpans = [];

    Iterable<Match> matches = regex.allMatches(addressString);
    for (Match match in matches) {
      String cssClass = match.group(1)!;
      String text = match.group(2)!;
      if (cssClass == 'country-name') {
        continue;
      }
      textSpans.add(
        TextSpan(
          text: text,
        ),
      );
      textSpans.add(
        const TextSpan(text: ', '),
      );
    }

    textSpans.removeLast();
    return textSpans;
  }
}
