http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex1_en/

Dependencies:   mbed RemoteIR SuperTweet ConfigFile EthernetNetIf

mylib/StreamFilter/StreamFilter.h

Committer:
shintamainjp
Date:
2010-11-04
Revision:
1:c4cfd136f9c7
Parent:
0:db299c5a18ba

File content as of revision 1:c4cfd136f9c7:

/**
 * =============================================================================
 * Stream filter for Twitter.
 * http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex1_en/
 * =============================================================================
 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * =============================================================================
 */

#include "mbed.h"

/**
 * Stream filter.
 */
class StreamFilter {
public:

    /**
     * Create.
     *
     * @param headtxt Head of a target.
     * @param tailtxt Tail of a target.
     */
    StreamFilter(const char *headtxt, const char *tailtxt);

    /**
     * Dispose.
     */
    ~StreamFilter();

    /**
     * Check state of done.
     *
     * @return Return true if it done.
     */
    bool done();

    /**
     * Reset state.
     */
    void reset();

    /**
     * Push a data to a internal buffer.
     *
     * @param c character.
     */
    void push(char c);

    /**
     * Get a content text.
     *
     * @param buf A pointer to a buffer.
     * @param bufsiz Size of the buffer.
     *
     * @return true if it succeed.
     */
    bool getContent(char *buf, size_t bufsiz);
private:
    int headcnt;
    int tailcnt;
    const char * head;
    const char * tail;
    char content[1024];
};