commonPrefix

Returns the common prefix of two ranges.

  1. auto commonPrefix(R1 r1, R2 r2)
  2. auto commonPrefix(R1 r1, R2 r2)
  3. auto commonPrefix(R1 r1, R2 r2)
    commonPrefix
    (
    R1
    R2
    )
    (
    R1 r1
    ,
    R2 r2
    )
    if (
    is(typeof(r1.front == r2.front))
    )
  4. auto commonPrefix(R1 r1, R2 r2)

Parameters

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

Suggestion Box / Bug Report