aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/regex/glob/glob_iterator.h
blob: e25481e594e0fc605ac2eb3351382f602a832a17 (plain) (blame)
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
32
33
34
35
36
#pragma once

#include "glob_compat.h"

#include <util/generic/noncopyable.h>
#include <util/generic/string.h>
#include <util/generic/yexception.h>

class TGlobPaths : TNonCopyable {
public:
    TGlobPaths(const char* pattern) {
        Impl.gl_pathc = 0;
        int result = glob(pattern, 0, nullptr, &Impl);
        Y_ENSURE(result == 0 || result == GLOB_NOMATCH, "glob failed");
    }

    TGlobPaths(const TString& pattern)
        : TGlobPaths(pattern.data())
    {
    }

    ~TGlobPaths() {
        globfree(&Impl);
    }

    const char** begin() {
        return const_cast<const char**>(Impl.gl_pathv);
    }

    const char** end() {
        return const_cast<const char**>(Impl.gl_pathv + Impl.gl_pathc);
    }

private:
    glob_t Impl;
};