/* * ! \brief unescape ASCII string into UTF-8. * counterpart to escape_path * * usually used for path-names only. * * This function allocates memory * which must be freed by the caller. */ char *unescape_path(const char *path, const char *flags) { char *unescaped_path; int processedBytes; if (serverInfo.LogLevel < LL_DEBUG) fprintf(serverInfo.LogFile, "unescape_path: got path %s\n", path); if (have_flag("U") || serverInfo.do_encode) { unescaped_path = malloc(MAX_FILENAME_LEN * sizeof(char)); if (unescaped_path == NULL) { fprintf(serverInfo.LogFile, "%s:%d:: malloc error.", __FILE__, __LINE__); return NULL; } processedBytes = u8_unescape(unescaped_path, MAX_FILENAME_LEN, (char *)path); if (serverInfo.LogLevel < LL_DEBUG) fprintf(serverInfo.LogFile, "unescape_path: path=\"%s\", processedBytes=%d, strlen=%zd\n", path, processedBytes, strlen(path)); return unescaped_path; } return (char *)path; }
//-------------------------------------------------------------- void testApp::update(){ while(receiver.hasWaitingMessages()){ ofxOscMessage m; receiver.getNextMessage(&m); lines.erase(lines.begin(),lines.end()); for (int i=0; i<m.getNumArgs(); i++){ msg = m.getArgAsString(i); std::strcpy(punt, msg.c_str()); u8_unescape(buf,255,punt); lines.push_back(buf); } } }
void artist_album_cb(json_value* v, void* user_ptr) { struct artist_album_state * s = (struct artist_album_state *) user_ptr; if (v->kv == JSON_KEY && v->length && strncmp(v->buffer + v->offset, "name", v->length) == 0) { s->got_name = 1; switch(s->lastfm_api_state) { case NOTHING: s->lastfm_api_state = ALBUM; break; case ALBUM: s->lastfm_api_state = ARTIST; break; case ARTIST: s->lastfm_api_state = NOTHING; } } if (v->kv == JSON_VALUE && s->got_name) { s->got_name = 0; if (s->lastfm_api_state == ALBUM) { ASSERT((v->length + 5) < 512, "Not enough room in the buffer to put the album name"); s->len_album = v->length; strncpy(s->buffer, v->buffer + v->offset, v->length); strncpy(s->buffer + s->len_album, ", by ", strlen(", by ")); s->len_album += strlen(", by "); } else if (s->lastfm_api_state == ARTIST) { ASSERT((s->len_album + v->length) < 512, "Not enough room in the buffer to put the artist name"); ASSERT(s->result_index < 30, "implement realloc for callback"); strncpy(s->buffer + s->len_album, v->buffer + v->offset, v->length); s->buffer[s->len_album + v->length] = 0; u8_unescape(s->buffer, 512, s->buffer); s->result[s->result_index] = malloc(strlen(s->buffer) + 1); strcpy(s->result[s->result_index], s->buffer); s->result_index++; s->lastfm_api_state = NOTHING; } } }