source: gaycko/trunk/src/helpers/str.c @ 4755

Last change on this file since 4755 was 4755, checked in by Jean-Yves Lamoureux, 9 years ago
  • Display rendering in caca window
File size: 1012 bytes
Line 
1/*
2 *  Gaycko        Text mode web browser
3 *  Copyright (c) 2011 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  This library is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12#include "str.h"
13#include <string.h>
14#include <stdlib.h>
15
16
17void strip_eol(char *str) {
18        int s = strlen(str)+1;
19    int i;
20   
21    for(i = 0; i < s; i++) {
22        if(str[i] == 10 ||
23           str[i] == 13) str[i] = ' ';
24    }
25   
26}
27
28void strip_spaces(char **os) {
29    char *str = *os;
30        int s = strlen(str)+1;
31    int i = 0;
32   
33    for(i = 0; i < s-1; i++) {
34        if(str[i] == ' ' &&
35           str[i+1] == ' ') {
36                memcpy(&str[i], &str[i+1], s-i);
37            s--;
38            str = realloc(str, s);
39        }
40    }
41}
Note: See TracBrowser for help on using the repository browser.