gi-glib-2.0.29: GLib bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | Safe-Inferred
Language | Haskell2010

GI.GLib.Structs.PatternSpec

Contents

- Exported types
- Methods
  - copy
  - equal
  - free
  - match
  - matchString
  - new

Description

A `GPatternSpec` struct is the 'compiled' form of a glob-style pattern.

The `patternMatchSimple` and `patternSpecMatch` functions match a string against a pattern containing '*' and '?' wildcards with similar semantics as the standard `glob()` function: '*' matches an arbitrary, possibly empty, string, '?' matches an arbitrary character.

Note that in contrast to `glob()`, the '/' character can be matched by the wildcards, there are no '[...]' character ranges and '*' and '?' can not be escaped to include them literally in a pattern.

When multiple strings must be matched against the same pattern, it is better to compile the pattern to a [struct`gLib`.PatternSpec] using `patternSpecNew` and use `patternSpecMatchString` instead of `patternMatchSimple`. This avoids the overhead of repeated pattern compilation.

Synopsis

- newtype PatternSpec = PatternSpec (ManagedPtr PatternSpec)
- patternSpecCopy :: (HasCallStack, MonadIO m) => PatternSpec -> m PatternSpec
- patternSpecEqual :: (HasCallStack, MonadIO m) => PatternSpec -> PatternSpec -> m Bool
- patternSpecFree :: (HasCallStack, MonadIO m) => PatternSpec -> m ()
- patternSpecMatch :: (HasCallStack, MonadIO m) => PatternSpec -> Word64 -> Text -> Maybe Text -> m Bool
- patternSpecMatchString :: (HasCallStack, MonadIO m) => PatternSpec -> Text -> m Bool
- patternSpecNew :: (HasCallStack, MonadIO m) => Text -> m PatternSpec

# Exported types

newtype PatternSpec Source #

Memory-managed wrapper type.

Constructors

PatternSpec (ManagedPtr PatternSpec) |

#### Instances

Instances details

Eq PatternSpec Source # |
Instance details Defined in GI.GLib.Structs.PatternSpec Methods (==) :: PatternSpec -> PatternSpec -> Bool Source # (/=) :: PatternSpec -> PatternSpec -> Bool Source #
GBoxed PatternSpec Source # |
Instance details Defined in GI.GLib.Structs.PatternSpec
ManagedPtrNewtype PatternSpec Source # |
Instance details Defined in GI.GLib.Structs.PatternSpec Methods toManagedPtr :: PatternSpec -> ManagedPtr PatternSpec Source #
TypedObject PatternSpec Source # |
Instance details Defined in GI.GLib.Structs.PatternSpec Methods glibType :: IO GType Source #
HasParentTypes PatternSpec Source # |
Instance details Defined in GI.GLib.Structs.PatternSpec
IsGValue (Maybe PatternSpec) Source # | Convert `PatternSpec` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.GLib.Structs.PatternSpec Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe PatternSpec -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe PatternSpec) Source #
type ParentTypes PatternSpec Source # |
Instance details Defined in GI.GLib.Structs.PatternSpec type ParentTypes PatternSpec = '[] :: [Type]

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

copy, equal, free, match, matchString.

#### Getters

None.

#### Setters

None.

## copy

patternSpecCopy Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> PatternSpec | `pspec`: a `PatternSpec`
-> m PatternSpec | Returns: a copy of `pspec`.

Copies `pspec` in a new `PatternSpec`.

Since: 2.70

## equal

patternSpecEqual Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> PatternSpec | `pspec1`: a `PatternSpec`
-> PatternSpec | `pspec2`: another `PatternSpec`
-> m Bool | Returns: Whether the compiled patterns are equal

Compares two compiled pattern specs and returns whether they will match the same set of strings.

## free

patternSpecFree Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> PatternSpec | `pspec`: a `PatternSpec`
-> m () |

Frees the memory allocated for the `PatternSpec`.

## match

patternSpecMatch Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> PatternSpec | `pspec`: a `PatternSpec`
-> Word64 | `stringLength`: the length of `string` (in bytes, i.e. `strlen()`, not `utf8Strlen`)
-> Text | `string`: the UTF-8 encoded string to match
-> Maybe Text | `stringReversed`: the reverse of `string` or `Nothing`
-> m Bool | Returns: `True` if `string` matches `pspec`

Matches a string against a compiled pattern. Passing the correct length of the string given is mandatory. The reversed string can be omitted by passing `Nothing`, this is more efficient if the reversed version of the string to be matched is not at hand, as `g_pattern_match()` will only construct it if the compiled pattern requires reverse matches.

Note that, if the user code will (possibly) match a string against a multitude of patterns containing wildcards, chances are high that some patterns will require a reversed string. In this case, it's more efficient to provide the reversed string to avoid multiple constructions thereof in the various calls to `g_pattern_match()`.

Note also that the reverse of a UTF-8 encoded string can in general not be obtained by `strreverse`. This works only if the string does not contain any multibyte characters. GLib offers the `utf8Strreverse` function to reverse UTF-8 encoded strings.

Since: 2.70

## matchString

patternSpecMatchString Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> PatternSpec | `pspec`: a `PatternSpec`
-> Text | `string`: the UTF-8 encoded string to match
-> m Bool | Returns: `True` if `string` matches `pspec`

Matches a string against a compiled pattern. If the string is to be matched against more than one pattern, consider using `g_pattern_match()` instead while supplying the reversed string.

Since: 2.70

## new

patternSpecNew Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `pattern`: a zero-terminated UTF-8 encoded string
-> m PatternSpec | Returns: a newly-allocated `PatternSpec`

Compiles a pattern to a `PatternSpec`.