The OpenD Programming Language

commonPrefix

Returns the common prefix of two ranges.

  1. auto commonPrefix(R1 r1, R2 r2)
    commonPrefix
    (
    alias pred = "a == b"
    R1
    R2
    )
    (
    R1 r1
    ,
    R2 r2
    )
    if (
    is(typeof(binaryFun!pred(r1.front, r2.front)))
    )
  2. auto commonPrefix(R1 r1, R2 r2)
  3. auto commonPrefix(R1 r1, R2 r2)
  4. auto commonPrefix(R1 r1, R2 r2)

Parameters

pred

The predicate to use in comparing elements for commonality. Defaults to equality "a == b".

r1 R1

A forward range of elements.

r2 R2

An input range of elements.

Return Value

Type: auto

A slice of r1 which contains the characters that both ranges start with, if the first argument is a string; otherwise, the same as the result of takeExactly(r1, n), where n is the number of elements in the common prefix of both ranges.

Examples

assert(commonPrefix("hello, world", "hello, there") == "hello, ");

See Also

Meta