예제 #1
0
//--------------------------------------
StreamingServicePlugin loadPlugin(const QString &directory) {
  QString metadataPath = findFileByExtension(directory, "ini");
  QString scriptPath = findFileByExtension(directory, "js");
  QString descPath = findFileByExtension(directory, "html");
  QString locale = QLocale::system().name().split("_")[0];
  QString translationPath = findTranslation(descPath, locale);
  if (!translationPath.isEmpty())
    descPath = translationPath;
  StreamingServicePlugin retVal;
  retVal.Code = readFileContent(scriptPath);
  retVal.Description = readFileContent(descPath);
  readMetadata(metadataPath, retVal);
  retVal.scriptPath = scriptPath;

  return retVal;
}
예제 #2
0
파일: main.c 프로젝트: palmyman/pa1-hw6
char * newSpeak(const char * text, const char * (*replace)[2]) {
    TNODE * dictionary;
    if (NULL == (dictionary = newDictionary(replace))) return NULL;

    unsigned int frontIndex = 0, tailIndex = 0, translationLenght = 0, maxLenght = DEFAULT_LENGHT;
    const char * match;
    char * translation = (char *) malloc(maxLenght + 1);
    translation[0] = '\0';
    for (frontIndex = 0; text[frontIndex] != '\0'; frontIndex++) {
        if (NULL != (match = findTranslation(dictionary, text + frontIndex, &tailIndex))) {
            frontIndex += tailIndex;
            translationLenght += strlen(match);
            while (translationLenght >= maxLenght) translation = reallocString(translation, maxLenght *= 2);
            strcat(translation, match);
        } else {
            if(translationLenght + 1 >= maxLenght) translation = reallocString(translation, maxLenght *= 2);
            translation[translationLenght++] = text[frontIndex];
            translation[translationLenght] = '\0';
        }        
    }

    freeDictionary(dictionary);
    return translation;
}