]> git.cryptolib.org Git - avr-crypto-lib.git/blob - string-extras.c
forgotten files
[avr-crypto-lib.git] / string-extras.c
1 /* string_extras.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /**
20  * \file        string_extras.c
21  * \author  Daniel Otte 
22  * \date    2006-05-16
23  * \license     GPLv3 or later
24  * 
25  */
26
27 #include <avr/pgmspace.h>
28 #include <ctype.h>
29
30 uint16_t stridentcnt_P(char* a, PGM_P b){
31         uint16_t i=0;
32         char c;
33         for(;;){
34                 c = pgm_read_byte(b++);
35                 if(*a != c || c=='\0')
36                         return i;
37                 i++;
38                 a++;
39         }
40 }
41
42 uint16_t firstword_length(char* s){
43         uint16_t ret=0;
44         while(isgraph(*s++))
45                 ret++;
46         return ret; 
47 }
48
49 char* strstrip(char* str){
50         if(!str)
51                 return str;
52         char* endptr;
53         while(*str && (*str==' ' || *str=='\t'))
54                 ++str;
55         endptr=str;
56         while(*endptr)
57                 ++endptr;
58         do{
59                 --endptr;
60         }while(*endptr==' ' || *endptr=='\t');
61         endptr[1]='\0';
62         return str;
63 }