Back to Documentations

Signature Description Parameters
template<binary_array T>
StlVecType<char>
starts_with(const char *col_name,
            const T &pattern) const;
This function determines if each item in the named column starts with the given pattern. The column type could be either a string or binary data. More precisely the column type could be any of the following:
    std::string
    std::basic_string<unsigned char>
    std::basic_string<std::byte>
    std::vector<char>
    std::vector<unsigned char>
    std::vector<std::byte>
        
It returns a vector of chars with the same size as the named column. A 0 value means the corresponding element does not start with the pattern. A 1 value means the corresponding element does start with the pattern.
T: Type of the named column
col_name: Name of the column
pattern: A string or binary pattern to match
template<binary_array T>
StlVecType<char>
ends_with(const char *col_name,
          const T &pattern) const;
This function determines if each item in the named column ends with the given pattern. The column type could be either a string or binary data. More precisely the column type could be any of the following:
    std::string
    std::basic_string<unsigned char>
    std::basic_string<std::byte>
    std::vector<char>
    std::vector<unsigned char>
    std::vector<std::byte>
        
It returns a vector of chars with the same size as the named column. A 0 value means the corresponding element does not end with the pattern. A 1 value means the corresponding element does end with the pattern.
T: Type of the named column
col_name: Name of the column
pattern: A string or binary pattern to match
static void test_starts_with()  {

    std::cout << "\nTesting starts_with( ) ..." << std::endl;

    std::vector<std::string>                idx = { "XXDnh\1", "XXD974h", "fbbgd", std::string("XXDoiendg\0\0", 11), "yehtfg", "mnbvcd", "dfgsret", "jhnbdfg", "XXDomagdfert",
                                                    "XXmj;'[-09", "XDimnaxcdf3", "207652234", "XXD", "XX" };
    std::vector<std::string>                s1 = { "XXDnh\1", "XXD974h", "fbbgd", std::string("XXDoiendg\0\0", 11), "yehtfg", "mnbvcd", "dfgsret", "jhnbdfg", "XXDomagdfert",
                                                   "XXmj;'[-09", "XDimnaxcdf3", "207652234", "XXD", "XX" };
    std::vector<std::vector<unsigned char>> v1 = { { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 8, 9, 10 },
                                                   { 100 },
                                                   { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 23, 30, 31, 32, 100 }
                                                 };
    std::vector<double>                     d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 10 };
    std::vector<int>                        i1 = { 22, 23, 24, 25, 99 };
    StrDataFrame                            df;

    df.load_data(std::move(idx),
                 std::make_pair("str_col", s1),
                 std::make_pair("col2", v1),
                 std::make_pair("col_3", d3),
                 std::make_pair("col_4", i1));

    const auto  res1 = df.starts_with<std::string>("str_col", "XXD");

    {
        std::vector<char>  out_res = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 };

        assert(res1 == out_res);
    }

    const auto  res2 = df.starts_with<std::vector<unsigned char>>("col2", { 8, 9, 10, 11 });

    {
         std::vector<char>  out_res = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };

        assert(res2 == out_res);
    }

    const auto  res3 = df.starts_with<std::string>(DF_INDEX_COL_NAME, "XXD");

    {
        std::vector<char>  out_res = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 };

        assert(res3 == out_res);
    }
}

// ----------------------------------------------------------------------------

static void test_ends_with()  {

    std::cout << "\nTesting ends_with( ) ..." << std::endl;

    std::vector<std::string>                idx = { "nh\1XXD", "974hXXD", "fbbgd", std::string("oiendg\0\0XXD", 11), "yehtfg", "mnbvcd", "dfgsret", "jhnbdfg", "omagdfertXXD",
                                                    "XXmj;'[-09", "XDimnaxcdf3", "207652234", "XXD", "XX" };
    std::vector<std::string>                s1 = { "nh\1XXD", "974hXXD", "fbbgd", std::string("oiendg\0\0XXD", 11), "yehtfg", "mnbvcd", "dfgsret", "jhnbdfg", "omagdfertXXD",
                                                   "XXmj;'[-09", "XDimnaxcdf3", "207652234", "XXD", "XX" };
    std::vector<std::vector<unsigned char>> v1 = { { 12, 13, 14, 20, 22, 23, 30, 31, 32, 100, 8, 9, 10, 11 },
                                                   { 12, 13, 14, 20, 22, 23, 30, 31, 32, 100, 8, 9, 10, 11 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 12, 13, 14, 20, 22, 23, 30, 31, 32, 100, 8, 9, 10, 11 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 8, 9, 10 },
                                                   { 100 },
                                                   { 12, 13, 14, 20, 22, 23, 30, 31, 32, 100, 8, 9, 10, 11 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 23, 30, 31, 32, 100 }
                                                 };
    std::vector<double>                     d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 10 };
    std::vector<int>                        i1 = { 22, 23, 24, 25, 99 };
    StrDataFrame                            df;

    df.load_data(std::move(idx),
                 std::make_pair("str_col", s1),
                 std::make_pair("col2", v1),
                 std::make_pair("col_3", d3),
                 std::make_pair("col_4", i1));

    const auto  res1 = df.ends_with<std::string>("str_col", "XXD");

    {
        std::vector<char>  out_res = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 };

        assert(res1 == out_res);
    }

    const auto  res2 = df.ends_with<std::vector<unsigned char>>("col2", { 8, 9, 10, 11 });

    {
         std::vector<char>  out_res = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };

        assert(res2 == out_res);
    }

    const auto  res3 = df.ends_with<std::string>(DF_INDEX_COL_NAME, "XXD");

    {
        std::vector<char>  out_res = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 };

        assert(res3 == out_res);
    }
}

C++ DataFrame