<?xml version="1.0"?>
<page xmlns="http://projectmallard.org/1.0/"
      type="topic"
      style="function"
      xmlns:api="http://projectmallard.org/experimental/api/"
      xmlns:ui="http://projectmallard.org/experimental/ui/"
      id="bson_iter_utf8">
  <info>
    <link type="guide" xref="bson_iter_t" group="function"/>
  </info>
  <title>bson_iter_utf8()</title>

  <section id="synopsis">
    <title>Synopsis</title>
    <synopsis><code mime="text/x-csrc"><![CDATA[
#define BSON_ITER_HOLDS_UTF8(iter) \
   (bson_iter_type ((iter)) == BSON_TYPE_UTF8)

const char *
bson_iter_utf8 (const bson_iter_t *iter,
                uint32_t          *length);
]]></code></synopsis>
  </section>

  <section id="parameters">
    <title>Parameters</title>
    <table>
      <tr><td><p>iter</p></td><td><p>A <code xref="bson_iter_t">bson_iter_t</code>.</p></td></tr>
      <tr><td><p>length</p></td><td><p>An optional location for the length of the resulting UTF-8 encoded string.</p></td></tr>
    </table>
  </section>

  <section id="description">
    <title>Description</title>
    <p>The <code xref="bson_iter_utf8">bson_iter_utf8()</code> function shall retrieve the contents of a BSON_TYPE_UTF8 element currently observed by <code>iter</code>.</p>
    <p>It is invalid to call this function while observing an element other than BSON_TYPE_UTF8.</p>
  </section>

  <section id="return">
    <title>Returns</title>
    <p>A UTF-8 encoded string that has not been modified or freed.</p>
    <p>It is suggested that the caller validate the content is valid UTF-8 before using this in other places. That can be done by calling <code xref="bson_utf8_validate">bson_utf8_validate()</code> or validating the underlying <code xref="bson_t">bson_t</code> before iterating it.</p>
    <p>Note that not all drivers use multi-byte representation for <code>\0</code> in UTF-8 encodings (commonly referred to as modified-UTF8). You probably want to take a look at the length field when marshaling to other runtimes.</p>
  </section>
</page>
