-static int
-bitStringNormalize(
- Syntax *syntax,
- struct berval *val,
- struct berval *normalized )
-{
- /*
- * A normalized bitString is has no extaneous (leading) zero bits.
- * That is, '00010'B is normalized to '10'B
- * However, as a special case, '0'B requires no normalization.
- */
- char *p;
-
- /* start at the first bit */
- p = &val->bv_val[1];
-
- /* Find the first non-zero bit */
- while ( *p == '0' ) p++;
-
- if( *p == '\'' ) {
- /* no non-zero bits */
- ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
- goto done;
- }
-
- normalized->bv_val = ch_malloc( val->bv_len + 1 );
-
- normalized->bv_val[0] = '\'';
- normalized->bv_len = 1;
-
- for( ; *p != '\0'; p++ ) {
- normalized->bv_val[normalized->bv_len++] = *p;
- }
-
- normalized->bv_val[normalized->bv_len] = '\0';
-
-done:
- return LDAP_SUCCESS;
-}
-