Length* newCoordsArray(const String& string, int& len) { unsigned length = string.length(); const UChar* data = string.characters(); StringBuffer spacified(length); for (unsigned i = 0; i < length; i++) { UChar cc = data[i]; if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.')) spacified[i] = ' '; else spacified[i] = cc; } RefPtr<StringImpl> str = StringImpl::adopt(spacified); str = str->simplifyWhiteSpace(); len = countCharacter(str->characters(), str->length(), ' ') + 1; Length* r = new Length[len]; int i = 0; int pos = 0; int pos2; while ((pos2 = str->find(' ', pos)) != -1) { r[i++] = parseLength(str->characters() + pos, pos2 - pos); pos = pos2+1; } r[i] = parseLength(str->characters() + pos, str->length() - pos); ASSERT(i == len - 1); return r; }
std::unique_ptr<Length[]> newCoordsArray(const String& string, int& len) { unsigned length = string.length(); StringBuffer<UChar> spacified(length); for (unsigned i = 0; i < length; i++) { UChar cc = string[i]; if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.')) spacified[i] = ' '; else spacified[i] = cc; } RefPtr<StringImpl> str = StringImpl::adopt(spacified); str = str->simplifyWhiteSpace(); len = countCharacter(*str, ' ') + 1; auto r = std::make_unique<Length[]>(len); int i = 0; unsigned pos = 0; size_t pos2; auto upconvertedCharacters = StringView(str.get()).upconvertedCharacters(); while ((pos2 = str->find(' ', pos)) != notFound) { r[i++] = parseLength(upconvertedCharacters + pos, pos2 - pos); pos = pos2+1; } r[i] = parseLength(upconvertedCharacters + pos, str->length() - pos); ASSERT(i == len - 1); return r; }
Length* newLengthArray(const String& string, int& len) { RefPtr<StringImpl> str = string.impl()->simplifyWhiteSpace(); if (!str->length()) { len = 1; return 0; } len = countCharacter(str->characters(), str->length(), ',') + 1; Length* r = new Length[len]; int i = 0; int pos = 0; int pos2; while ((pos2 = str->find(',', pos)) != -1) { r[i++] = parseLength(str->characters() + pos, pos2 - pos); pos = pos2+1; } ASSERT(i == len - 1); // IE Quirk: If the last comma is the last char skip it and reduce len by one. if (str->length()-pos > 0) r[i] = parseLength(str->characters() + pos, str->length() - pos); else len--; return r; }
std::unique_ptr<Length[]> newLengthArray(const String& string, int& len) { RefPtr<StringImpl> str = string.impl()->simplifyWhiteSpace(); if (!str->length()) { len = 1; return nullptr; } len = countCharacter(*str, ',') + 1; auto r = std::make_unique<Length[]>(len); int i = 0; unsigned pos = 0; size_t pos2; auto upconvertedCharacters = StringView(str.get()).upconvertedCharacters(); while ((pos2 = str->find(',', pos)) != notFound) { r[i++] = parseLength(upconvertedCharacters + pos, pos2 - pos); pos = pos2+1; } ASSERT(i == len - 1); // IE Quirk: If the last comma is the last char skip it and reduce len by one. if (str->length()-pos > 0) r[i] = parseLength(upconvertedCharacters + pos, str->length() - pos); else len--; return r; }
void Font::removeCharacter(int id) { assert(id>=0 && id<countCharacter()); m_listCharacter.erase(m_listCharacter.begin() + id); }
Character* Font::characterAtIndex(int id) { assert(id>=0 && id<countCharacter()); return &m_listCharacter.at(id); }
std::vector<triangle> OBJFileReader::getFacesFromLine(char* line, const OBJFileData* data, material use_mtl) { std::vector<triangle> triangles; int vertex_count = countCharacter(' ', line); char **all_vertices = (char**) malloc (sizeof(char*)*vertex_count + 1); strtok(line, " "); for(int i = 0; i < vertex_count-1; i++) { all_vertices[i] = strtok(NULL, " "); } all_vertices[vertex_count-1] = strtok(NULL, " \n\0"); for(int vert = 1; vert < vertex_count - 1; vert++) { char* vertices[3] = {all_vertices[0], all_vertices[vert], all_vertices[vert+1]}; int vertex_indices[3] = {-1, -1, -1}; int texture_coord_indices[3] = {-1, -1, -1}; int normal_indices[3] = {-1, -1, -1}; // Boolean containing whether we haven't declared a normal. bool undeclared_normal = false; bool has_texture = false; for(int i = 0; i < 3; i++) { int size = strlen(vertices[i]); std::string data[] = {std::string(), std::string() ,std::string()}; int counter = 0; // The amount of '/' we have encountered. for(int j = 0; j < size; j++) { if(vertices[i][j] == '/') { counter++; } else { data[counter].push_back(vertices[i][j]); } } vertex_indices[i] = atoi(data[0].data()); if(counter >= 1) { if(data[1].size()) { texture_coord_indices[i] = atoi(data[1].data()); has_texture = true; } } if(counter == 2) normal_indices[i] = atoi(data[2].data()); else undeclared_normal = true; } vertex first(data->vertexList[vertex_indices[0]]); vertex secnd(data->vertexList[vertex_indices[1]]); vertex third(data->vertexList[vertex_indices[2]]); first.setColour(use_mtl.diffuse); secnd.setColour(use_mtl.diffuse); third.setColour(use_mtl.diffuse); if(has_texture && use_mtl.texture) { //printf("has texture!! %p\n", use_mtl.texture); first.setTexCoord(data->textureCoordList[texture_coord_indices[0]]); secnd.setTexCoord(data->textureCoordList[texture_coord_indices[1]]); third.setTexCoord(data->textureCoordList[texture_coord_indices[2]]); } else { //printf("has no texture\n"); has_texture = false; } triangle new_triangle(first, secnd, third); if(has_texture) new_triangle.setTexture(use_mtl.texture); if(undeclared_normal) { new_triangle.generateNormals(); } else { new_triangle[0].setNormal(data->normalList[normal_indices[0]]); new_triangle[1].setNormal(data->normalList[normal_indices[1]]); new_triangle[2].setNormal(data->normalList[normal_indices[2]]); } float4 avg_normal = new_triangle.getAverageNormal(); //Check for NaN if( new_triangle.getAverageNormal()[0] == new_triangle.getAverageNormal()[0] || new_triangle.getAverageNormal()[1] == new_triangle.getAverageNormal()[1] || new_triangle.getAverageNormal()[2] == new_triangle.getAverageNormal()[2]) triangles.push_back(new_triangle); } return triangles; }
std::map<std::string,std::vector<std::string> > StringTools::tabDelimitedSpreadsheetFileToStringMap(const std::string& tabDelimitedSpreadsheetFileName) { const char rowDelim = '\n'; const char fieldDelim = '\t'; const char surplusRowDelim = '\r'; std::map<std::string,std::vector<std::string> > result; std::vector<std::string> headerEntries; std::map<std::string,std::vector<std::string> >::iterator resultMapIterator; std::vector<std::string> emptyStringVector; std::string tmpString; int numberOfFieldDelims; std::istringstream iStringStream; char* inputFileName = new char [tabDelimitedSpreadsheetFileName.size()+1]; std::strcpy (inputFileName, tabDelimitedSpreadsheetFileName.c_str()); std::ifstream spreadsheetFile(inputFileName); delete[] inputFileName; if( !(spreadsheetFile) ) { std::string fileExistErrorMessageString = "Following file cannot be found:\n"; fileExistErrorMessageString.append(tabDelimitedSpreadsheetFileName); fileExistErrorMessageString.append("\n"); char* fileExistErrorMessageNotConst = new char [fileExistErrorMessageString.size()+1]; std::strcpy (fileExistErrorMessageNotConst,fileExistErrorMessageString.c_str()); const char *const fileExistErrorMessage = fileExistErrorMessageNotConst; throw(fileExistErrorMessage); } std::copy(std::istreambuf_iterator<char>(spreadsheetFile), std::istreambuf_iterator<char>(), std::back_inserter(tmpString)); spreadsheetFile.close(); std::replace(tmpString.begin(),tmpString.end(),surplusRowDelim,rowDelim); removeAdjacentDuplicatesOfCertainCharacter(tmpString,rowDelim); std::istringstream spreadsheet; spreadsheet.str(tmpString); tmpString.clear(); for(bool firstLine = true; std::getline(spreadsheet,tmpString,rowDelim); ) { removeAdjacentDuplicatesOfCertainCharacter(tmpString,fieldDelim); removeSingleCertainCharacterFromBeginning(tmpString,fieldDelim); removeSingleCertainCharacterFromEnd(tmpString,fieldDelim); iStringStream.clear(); iStringStream.str( tmpString ); numberOfFieldDelims = countCharacter(tmpString,fieldDelim); tmpString.clear(); if(firstLine) { for(;std::getline(iStringStream,tmpString,fieldDelim);tmpString.clear()) { headerEntries.push_back(tmpString); result[tmpString] = emptyStringVector; } firstLine = false; } else { if( numberOfFieldDelims >= (headerEntries.size()-1) ) { for(std::vector<std::string>::const_iterator currentHeaderEntry = headerEntries.begin(); currentHeaderEntry < headerEntries.end(); ++currentHeaderEntry) { resultMapIterator = result.find(*currentHeaderEntry); std::getline(iStringStream,tmpString,fieldDelim); resultMapIterator->second.push_back(tmpString); tmpString.clear(); } } } } if( (result.begin())->second.size() == 0 ) { std::string noSufficientRowErrorMessageString = "The following file does not contain any row with the minimum number of entries defined by the header line:\n"; noSufficientRowErrorMessageString.append(tabDelimitedSpreadsheetFileName); noSufficientRowErrorMessageString.append("\n"); char* noSufficientRowErrorMessageNotConst = new char [noSufficientRowErrorMessageString.size()+1]; std::strcpy (noSufficientRowErrorMessageNotConst,noSufficientRowErrorMessageString.c_str()); const char *const noSufficientRowErrorMessage = noSufficientRowErrorMessageNotConst; throw(noSufficientRowErrorMessage); } return result; }